408211: GYM103055 E Specially Super Rare

Memory Limit:512 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Specially Super Raretime limit per test2.0 smemory limit per test512 megabytesinputstandard inputoutputstandard output

A string is palindromic iff it reads the same right to left as left to right. For example "abba", "zjcpcjz" are palindromes. Chenjb loves palindromes, and he owns an extremely long palindrome string $$$S$$$.

Yesterday, RMB player Chenjb paid to open $$$m$$$ boxes in a popular mobile game. Every time he pays to open a box, he will get an item called "SSR" (Specially Super Rare) with the probability of $$$0.003\%$$$. Every time Chenjb got such an item, he would either delete a character or modify a character in his own string $$$S$$$ to celebrate his luck.

Today, Chenjb wants his string $$$S$$$ to be palindrome again by removing some characters from $$$S$$$. Please write a program to help him find the longest palindromic subsequence of the current string $$$S$$$.

Input

The input contains only a single case.

The first line contains a string $$$S$$$ which consists of $$$n$$$ ($$$1 \leq n \leq 10^7$$$) lower-case English letters, denoting the current string.

The second line contains a single integer $$$m$$$ ($$$1\leq m\leq 10^7$$$), denoting the number of boxes Chenjb opened yesterday.

Output

Print a single line containing an integer, denoting the length of the longest subsequence of $$$S$$$.

ExampleInput
abadba
31274
Output
5

加入题单

上一题 下一题 算法标签: