EPALIN - Extend to Palindrome

Your task is, given an integer N, to make a palindrome (word that reads the same when you reverse it) of length at least N (1 <= N <= 100,000). Any palindrome will do.

Easy, isn't it? That's what you thought before you passed it on to your inexperienced team-mate. When the contest is almost over, you find out that that problem still isn't solved. The problem with the code is that the strings generated are often not palindromic. There's not enough time to start again from scratch or to debug his messy code.

Seeing that the situation is desperate, you decide to simply write some additional code that takes the output and adds just enough extra characters to it to make it a palindrome and hope for the best. Your solution should take as its input a string and produce the smallest palindrome that can be formed by adding zero or more characters at its end. The input string will consist of only upper and lower case letters.

Example

Input:
aaaa
abba
amanaplanacanal
xyz

Output:
aaaa
abba
amanaplanacanalpanama
xyzyx
Note:
1. All palindromes are considered case-sensitive (i.e. 'Aa' is not a palindrome).
2. Large I/O. Be careful in certain languages.

Added by:Muntasir Azam Khan
Date:2009-03-22
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO
Resource:Own problem, used in Next Generation Contest 5

hide comments
2015-07-11 11:20:04 arjundabra
we have to read input till EOF or there is just a single input???
2015-05-20 15:52:20 vivek keshore
I have tested all types of cases, and took care about case sensitivity as well. Still I am getting wrong answer. Can someone please tell me some tricky cases.
If a space is there in the input, then we have to strip that space, or consider it as a character.

Last edit: 2015-05-20 15:55:48
2015-05-18 16:51:51 eightnoteight
excellent problem, really enjoyed solving it.
2015-02-11 20:04:09 Archit Jain
easy but enjoyed solving it
2014-12-21 17:19:45 Paul Luyo
Be careful with blanks
2012-02-13 07:22:52 Muntasir Azam Khan
@Nic Roets: Judge solution outputs an 80 character string for your input.
Similar problems may have appeared before or after this one, this particular one was used in an online contest in 2008 (http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=13&page=show_contest&contest=202).
2011-10-24 22:34:18 Nic Roets
This problem appeared in a contest in 2005
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.