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



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

Output



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

Sample test(s)

Input



aaba

2



Output



6



Input



aaabbbb

2



Output



6



Input



abracadabra

10



Output



20

Note

A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ 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.

暴力枚举全部情况

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std; char str[205]; int main(){
int n;
while(cin>>str>>n){
int len = strlen(str);
int L = len+n-(len+n)%2; //保证长度为偶数
if(len <= n){
cout<<L<<endl;
continue;
}
int maxlen = 0;
for(int i=0; i<len; i++){ //枚举起始位置
for(int j=1; i+j-1<=len-1; j++){ //枚举一半的长度
int cnt = 0;
for(int k=i; k<=i+j-1; k++){ //推断
if(len <= k+j && k+j < len+n) cnt++; //下标
else if(str[k] == str[k+j]) cnt++;
}
if(cnt == j && 2*cnt > maxlen)
maxlen = 2*cnt;
}
}
cout<<maxlen<<endl;
}
return 0;
}

CF B. Kolya and Tandem Repeat的更多相关文章

  1. cf443B Kolya and Tandem Repeat

    B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. Codeforces 443 B. Kolya and Tandem Repeat

    纯粹练JAVA.... B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megab ...

  3. Kolya and Tandem Repeat

     Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. codeforces 443 B. Kolya and Tandem Repeat 解题报告

    题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...

  5. Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

    本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...

  6. Codeforces 443 B Kolya and Tandem Repeat【暴力】

    题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚 ...

  7. CodeForces 443B Kolya and Tandem Repeat

    题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. ...

  8. CF 584B Kolya and Tanya

    题目大意:3n个人围着一张桌子,给每个人发钱,可以使1块.2块.3块,第i个人的金额为Ai.若存在第个人使得Ai + Ai+n + Ai+2n != 6,则该分配方案满足条件,求所有的满足条件的方案数 ...

  9. Codeforces Round 253 (Div. 2)

    layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...

随机推荐

  1. boost的link 和 runtime-link,搭配shared 和 static

    转自:http://blog.csdn.net/yasi_xi/article/details/8660549 link:生成动态链接库/静态链接库.生成动态链接库需使用shared方式,生成静态链接 ...

  2. MySQL_PHP学习笔记_2015_0614_PHP传参总结_URL传参_表单传参

    1. PHP 传参总结   1.1 url 传参     解析方法(下面两种解读方式均可以): $firstName1 = $_GET['firstName']; $firstName2 = $_RE ...

  3. (转载)OC学习篇之---Foundation框架中的其他类(NSNumber,NSDate,NSExcetion)

    前一篇说到了Foundation框架中的NSDirctionary类,这一一篇来看一下Foundation的其他常用的类:NSNumber,NSDate,NSException. 注:其实按照Java ...

  4. Scrum角色

    产品负责人(Product Owner)的职责如下: 确定产品的功能. 决定发布的日期和发布内容. 为产品的profitability       of the product (ROI)负责. 根据 ...

  5. BitmapData类介绍

    今天介绍另外一个比较常用和中高级难度的类:BitmapData 用好这个类,可以说是半支脚踏入了Flash高手的大门···(主要是不是太多的人精通这个··呵呵··)我也可以趁这篇文章的机会好好巩固+学 ...

  6. Google Glass应用开发探索

    摘要:2012年6月的Google开发者大会上,作者有幸预定到了Google Glass.8个月后,她收邀参加了Google纽约总部举行的Google Glass Foundry开发大赛.在为期两天的 ...

  7. sysctl.conf

    linux系统接口 允许改变正在运作linux系统接口Tcp/IP堆栈和虚拟内存系统的高级选项 用来控制Linux网络配置/proc/sys/net/core/ TCP/IP参数修改添加到/etc/s ...

  8. Physicals

    [Physicals] The physics simulation in Sprite Kit is performed by adding physics bodies to scenes. [T ...

  9. quartz中关键类

    job job是一个接口,你对某一类job的定义,可以通过实现该接口来实现.例如为销售报告定义一个SalesReportJob,包含变量name. job可以使用的几个注解 @DisallowConc ...

  10. ubuntu14.04恢复系统默认中文字体

    今天 Ubuntu14.04已发布就进行了更新,在配置过程中,无意安装了某些中文字体,导致系统的中文字体极其难看,根据网上说的修改配置文件和tweak 修改的方法都不能解决,最终找到的解决办法(htt ...