#C3138. Lexicographically Smallest Palindrome
Lexicographically Smallest Palindrome
Lexicographically Smallest Palindrome
Given a string s
consisting only of lowercase English letters, you are required to rearrange the characters to form a palindrome. Among all possible palindromes, output the lexicographically smallest one. If it is impossible to form any palindrome from s
, output IMPOSSIBLE
.
A palindrome is a string that reads the same forwards and backwards. The lexicographical order is defined based on the usual alphabetical order.
Note: The input will be provided to your program via standard input (stdin) and the expected output should be printed to standard output (stdout).
Examples:
- For s = "aabb", one possible palindrome is "abba".
- For s = "abc", no palindrome can be formed, so the output is "IMPOSSIBLE".
- For s = "aaabbbb", the output should be "abbabba".
inputFormat
The input consists of a single line containing a string s
of lowercase English letters.
For example:
aabb
outputFormat
Output the lexicographically smallest palindrome that can be formed by rearranging the letters of s
, or print IMPOSSIBLE
if no palindrome can be formed.
For example:
abba## sample
aabb
abba
</p>