cswork / OAOpen practice workspace

NvidiaOA #5

Break a Palindrome

Estimated MediumJudge-ready

Topics (AI-labelled)StringsGreedy

Given a lowercase palindrome, change exactly one character so that the result is not a palindrome, is strictly smaller than the original string, and is the lexicographically smallest among all valid results; if there is no solution, output IMPOSSIBLE.

This site uses a standard input/output protocol.

Input

One line containing a lowercase palindrome of length 1..1000.

Output

Output the valid string or the uppercase IMPOSSIBLE.

Example 1

Input:

aaabbaaa

Output:

aaaabaaa

Example 2

Input:

aba

Output:

IMPOSSIBLE

Example 3

Input:

bb

Output:

ab

Example notes

Example 1: change the b at index 3 to a, giving aaaabaaa. Example 2: changing the center still gives a palindrome, and the other a characters cannot be lowered, so IMPOSSIBLE. Example 3: changing the first character to a gives ab, which is better than ba.

Editorial

Loading solution…