Largest Lexicographical Rotation II
Practice
4.5 (13 votes)
Algorithms
Approved
Medium
Open
String manipulation
Problem
93% Success 5371 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bidhan studies at the University of Dhaka. Recently he noticed that, some of the university students are speaking a strange language. The words used in that language are not meaningful to him. After some investigation he learned that, the students use the largest lexicographical rotation of words instead of the original words.

Word p' is a rotation of word p if,
p = a + b and
p' = b + a , where a and b are some strings ( possibly empty ) and + sign denotes the concatenation operation. w, the largest lexicographical rotation of p is the lexicographically biggest one among all possible p's.

Given a string, output it's largest lexicographical rotation.

Input

The only line of the input contains next p.

Output

Output a single line containing the largest lexicographical rotation of p.

Constraints

  • 1|p|4 × 106. ( |p| denotes the size of p. )
  • p will contain lowercase English letters only.

Example

Input:
bidhan

Output: nbidha

Explanation

The rotations of string bidhan are

bidhan,
idhanb,
dhanbi,
hanbid,
anbidh and
nbidha.

nbidha is lexicographically biggest among all of them.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
String AlgorithmsAlgorithmsString Searching
Points:30
2 votes
Tags:
AlgorithmsGreedy AlgorithmsMediumString Manipulationhiring
Points:30
9 votes
Tags:
AlgorithmsString Manipulation