#K95657. Rearrange String into Two Identical Halves

    ID: 38912 Type: Default 1000ms 256MiB

Rearrange String into Two Identical Halves

Rearrange String into Two Identical Halves

Given a string ( s ), determine whether it can be rearranged to form two identical substrings of equal length. In other words, check if there exists a rearrangement of ( s ) such that it can be written in the form ( T T ) where ( T ) is a non-empty string. If such a rearrangement exists, output one valid rearrangement; otherwise, output "IMPOSSIBLE".

Note: The string should have even length and every character in ( s ) must appear an even number of times to form two identical halves. In the valid case, one simple approach is to sort the characters and then form the half substring ( T ) by taking half of the counts for each character, finally output ( T ) concatenated with ( T ).

inputFormat

The input is read from standard input (stdin). It consists of a single line containing the string ( s ).

outputFormat

Output to standard output (stdout) a string which is one valid rearrangement of ( s ) into the form ( T T ) if possible. If no valid rearrangement exists, output "IMPOSSIBLE".## sample

aabbcc
abcabc