Mikhail strikes back
Time limit5sMemory limit4 MB
Insert the fewest letters into a string of up to 15000 characters to make it a palindrome, then print the count and one resulting palindrome.
- Level
Medium6 of 10
- Topics
- String, Dynamic programming, Divide and conquer
- Solved
- No attempts yet
Problem
Note the unusual memory limit in this problem.
Vasya loves taking part in informatics olympiads. He has realized that he enjoys string problems the most. Recently he was impressed by a newly invented data structure, the palindrome tree. It can find palindromes even where there are none.
Vasya wants the palindrome tree to create palindromes from strings instead of searching for them. He only wants to insert characters at arbitrary positions of a string. He does not want to delete or change any existing character, since he values the strings he is given. Help him find a way to turn a given string into a palindrome.
Input
The only line contains a non-empty string of lowercase English letters. Its length does not exceed characters.
Output
On the first line, print , the minimum number of characters that must be added to to make it a palindrome. On the second line, print a string , a palindrome obtained from by adding exactly characters, so that .
Hint
A palindrome is a string that reads the same in both directions. For example, "a" and "abraarba" are palindromes, while "ab" and "abracadabra" are not.