CF 443B (253B) Kolya and Tandem Repeat

Source: Internet
Author: User

Kolya and Tandem Repeattime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Kolya got stringSFor his birthday, the string consists of small English letters. He immediately addedKMore characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of lengthLAs a substring. How large cocouldLBe?

See notes for definition of a tandem repeat.

Input

The first line containsS(1 hour ≤ hour |S| Limit ≤ limit 200). This string contains only small English letters. The second line contains numberK(1 digit ≤ DigitKLimit ≤ limit 200)-the number of the added characters.

Output

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

Sample test (s) Input
aaba2
Output
6
Input
aaabbbb2
Output
6
Input
abracadabra10
Output
20
Note

A tandem repeat of length 2NIs stringS, Where for any positionI(1 digit ≤ DigitILimit ≤ limitN) The following condition fulfills:SISignature = SignatureSIRegion + RegionN.

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


Enumerative. The characters are not long.


The AC code is as follows:


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define M 100005 # define ll long longusing namespace std; int main () {char a [10005]; int k; cin> a> k; int l = strlen (a); int I, m, j, o, ans; m = l + k; m = m-m % 2; if (k> = l) {cout <m <endl; return 0 ;} // remember this case int max = 0; for (I = 0; I <l; I ++) // start of the character {for (j = 1; j <= l-I; j ++) // length of the enumerated characters {for (o = I, ans = 0; o <I + j; o ++) {if (o + j> = l & o + j <l + k) ans ++; else if (a [o] = a [o + j]) ans ++;} if (ans = j & 2 * ans> max) // check whether the compliance is true. max = 2 * ans ;}} cout <max <endl; return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.