#P1368. The Block Craft Transformation
The Block Craft Transformation
The Block Craft Transformation
Xiaomin and Xiaoyan are two good friends who are playing a magical game called Minecraft. They are constructing a long craft made of blocks. However, the blocks are in a random order and due to machine constraints, they can only perform one operation: move the leftmost block to the rightmost end.
The beauty of a craft is determined by a lexicographical comparison: compare from the beginning, and at the first position where the two blocks differ, the craft with the block having a lower defect degree (i.e. smaller value) is considered more beautiful. If all corresponding blocks are identical, then the two crafts are equally beautiful.
Given the original arrangement of blocks represented as a string, you are to determine the most beautiful craft that can be obtained by applying at most one operation; that is, compare the original craft with the one obtained by moving the leftmost block to the end and output the lexicographically smaller one.
Mathematically, if the block sequence is represented by s, and the shifted sequence is given by \( s' = s_{2}s_{3}\cdots s_{n}s_{1} \), then you need to output \( min(s, s') \) under lexicographical order.
inputFormat
The input consists of a single line containing a non-empty string s representing the order of blocks. The string only contains visible characters.
outputFormat
Output a single string which is the lexicographically smaller one between the original string and the one obtained by moving its first character to the end.
sample
abc
abc