Make Palindrome

By definition palindrome is a string which is not changed when reversed. “MADAM” is a nice example of palindrome. It is an easy job to test whether a given string is a palindrome or not. But it may not be so easy to generate a palindrome. Here we will make a palindrome generator which will take an input string and return a palindrome. You can easily verify that for a string of length n, no more than (n − 1) characters are required to make it a palindrome. Consider ‘abcd’ and its palindrome ‘abcdcba’ or ‘abc’ and its palindrome ‘abcba’. But life is not so easy for programmers!! We always want optimal cost. And you have to find the minimum number of characters required to make a given string to a palindrome if you are allowed to insert characters at any position of the string. Input Each input line consists only of lower case letters. The size of input string will be at most 1000. Input is terminated by EOF. Output For each input print the minimum number of characters and such a palindrome separated by one space in a line. There may be many such palindromes. Any one will be accepted. Sample Input abcd aaaa abc aab abababaabababa pqrsabcdpqrs Sample Output 3 abcdcba 0 aaaa 2 abcba 1 baab 0 abababaabababa 9 pqrsabcdpqrqpdcbasrqp