Problem list
Log in
#coci00057 · COCI 2007/2008 Contest 4

Lektira

Silver V 1.0 s 32 MB

Mario is making up silly games again instead of reading Dostoevsky for school. The rules of his newest game follow.

First he chooses a random word from the book. Then he splits the word in two arbitrary places to get three separate words.

After that he reverses the order of the letters in each of those three words (exchanges the first and last letters, the second and second last and so on).

Finally, he puts the three words back together in the same order in which they were before splitting.

The goal of the game is to obtain the lexicographically smallest word possible. In other words, of all words that can be obtained by the above procedure, find one which would be earliest in a dictionary.

Write a program that plays Mario's game perfectly.

Input

The first and only line of input contains Mario's chosen word, a string of lowercase letters of the English alphabet with no spaces.

The input word will be between $3$ and $50$ characters long (inclusive).

Output

Output the best word on a single line.

Example 1

Input
dcbagfekjih
Output
abcdefghijk

Example 2

Input
mobitel
Output
bometil

Example 3

Input
anakonda
Output
aanadnok
Source
COCI 2007/2008 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code