3151.Kolya and Tandem Repeat

Time Limit: 1s Memory Limit: 256MB

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

See notes for definition of a tandem repeat.

Input Format(From the terminal/stdin)

The first line contains s (1 \le |s| \le 200). This string contains only small English letters. The second line contains number k (1 \le k \le 200) - the number of the added characters.

Output Format(To the terminal/stdout)

Print a single number - the maximum length of the tandem repeat that could have occurred in the new string.

Sample Input 1

Copy
aaba
2
    \n
 \n

Sample Output 1

Copy
6
 \n

Sample Input 2

Copy
aaabbbb
2
       \n
 \n

Sample Output 2

Copy
6
 \n

Sample Input 3

Copy
abracadabra
10
           \n
  \n

Sample Output 3

Copy
20
  \n

Hints

A tandem repeat of length 2n is string s, where for any position i (1 \le i \le n) the following condition fulfills: si=si+n.

In the first sample Kolya could obtain a string aabaab, in the second - aaabbbbbb, in the third - abracadabrabracadabra.

Submit

请先 登录

© 2025 FAQs