#K52127. Rearrange to Form Palindrome
Rearrange to Form Palindrome
Rearrange to Form Palindrome
Given a string S consisting of lowercase English letters, determine if it is possible to rearrange its characters to form a palindrome. A palindrome is a string that reads the same backward as forward.
If it is possible, output a valid palindrome constructed by placing half of the occurrences of each character in order, then a middle character (if any exists), and finally the reverse of the first half. Otherwise, output IMPOSSIBLE
.
For example, for the input aabb
, one valid output is abba
.
inputFormat
A single line of input containing a string S with only lowercase English letters.
outputFormat
If it is possible to rearrange S to form a palindrome, print the palindrome. Otherwise, print IMPOSSIBLE
.## sample
aabb
abba
</p>