#K95347. Anti-Anagram Derangement
Anti-Anagram Derangement
Anti-Anagram Derangement
Given a string ( s ) consisting of lowercase English letters, your task is to produce an anti‐anagram of ( s ) if possible. An anti‐anagram is defined as a permutation ( t ) of the characters of ( s ) such that for every index ( i ) (with 1-based indexing) the character ( t_i ) is different from ( s_i ). In other words, if ( s = s_1s_2\cdots s_n ), you need to find a permutation ( t = t_1t_2\cdots t_n ) satisfying
[
t_i \neq s_i \quad \text{for all } i = 1, 2, \ldots, n.
]
If no such permutation exists, output IMPOSSIBLE
.
The input is read from standard input and the output is written to standard output. Note that if the string is of length one or if all characters are identical (or if a valid rearrangement is impossible), the correct answer is IMPOSSIBLE
.
inputFormat
The input consists of a single line containing the string ( s ) (a sequence of lowercase English letters).
outputFormat
Output a single line. If an anti‐anagram of ( s ) exists, print one valid anti‐anagram; otherwise, print IMPOSSIBLE
.## sample
abc
cab
</p>