Under construction

Still being built. Things may change

Splitting a Word

Interview

Time limit2sMemory limit128 MB

Summary
Split a lowercase word into three nonempty parts, reverse each part, and find the lexicographically smallest concatenation among all splits.
Level

Easy2 of 10

Topics
String, Brute force, Implementation
Solved
No attempts yet

Problem

You are given a word consisting only of lowercase English letters. Split the word into three contiguous parts. Each part must have length at least 1.

Reverse each part separately, then concatenate the reversed parts in the same order as the split. Among all strings that can be made this way, find the lexicographically smallest one.

Input

The first line contains a word consisting of lowercase English letters. Its length is between 3 and 50, inclusive.

Output

Output the lexicographically smallest string that can be made.

Examples1

  1. Example 1

    Input
    mobitel
    
    Expected output
    bometil