cswork / OAOpen practice workspace

VisaOA #6

Lexicographically Smallest by Reversing Prefix/Suffix

Estimated EasyJudge-ready

Topics (AI-labelled)Strings

Given a lowercase string, reverse exactly one non-empty prefix or suffix exactly once, and find the lexicographically smallest of all results.

Input

A non-empty lowercase string; this site adds |word|≤2000 so that all candidates can be enumerated directly.

Output

Output the smallest result.

Example 1

Input:

edcba

Output:

abcde

Example 2

Input:

a

Output:

a

Example 3

Input:

bac

Output:

abc

Editorial

Loading solution…