cswork / OAOpen practice workspace

AmazonOA #183

Find Obfuscate Message

Estimated MediumJudge-ready

Topics (AI-labelled)StringsGreedy

Choose exactly one non-empty substring and rotate it right by 1, i.e. move its last character to the front and shift the other characters right. Find the lexicographically smallest resulting string. Choosing a single character, which leaves the string unchanged, is allowed.

Input

One line containing a lowercase string of length 1..100000.

Output

Output the smallest string.

Example 1

Input:

aahhab

Output:

aaahhb

Example 2

Input:

abc

Output:

abc

Example 3

Input:

cbaba

Output:

acbab

Example notes

The answers are aaahhb, abc and acbab.

Editorial

Loading solution…