eolymp
bolt
Try our new interface for solving problems
Problems

Inexact string

Inexact string

We say that the lines \textbf{a} and \textbf{b} are\textit{ }\textbf{k}\textit{ }differences, if the lengths of these lines are identical, and the characters in positions with the same numbers same everything, except the \textbf{k} pieces. For example, line \textbf{ABABAC} and \textbf{BBABAB} have \textbf{2} differences. In this line \textbf{S} of length \textbf{N} symbols and the number of \textbf{k} is required to find two strings of equal length, starting from different positions, and having no more than \textbf{k} differences. The line consists of uppercase Latin characters. \InputFile The input file contains the first line an integer \textbf{k}, in the second - the string \textbf{S}. \OutputFile The output file should contain an integer number - the length of the longest matched string, or \textbf{0} (zero) if no solution exists. \textbf{0} ≤ \textbf{k} ≤ \textbf{N} ≤ \textbf{1000}
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
Z
Output example #1
0