#K73732. Lexicographically Smallest Cyclic Rotation

    ID: 34041 Type: Default 1000ms 256MiB

Lexicographically Smallest Cyclic Rotation

Lexicographically Smallest Cyclic Rotation

Given a string \( S \), determine the lexicographically smallest string that can be obtained by cyclically rotating \( S \). A cyclic rotation is defined by moving a prefix of the string to its end. For example, if \( S = "bca" \), its cyclic rotations are "bca", "cab", and "abc". The answer in this case is "abc" because it is the smallest in lexicographical order.

Note: A string \( A \) is said to be lexicographically smaller than string \( B \) if either \( A \) is a prefix of \( B \) (and \( A \) \( \neq \) \( B \)), or there exists an index \( i \) such that \( A_j = B_j \) for all \( j < i \) and \( A_i < B_i \).

The task is to implement a program that reads a string from standard input (stdin) and prints the lexicographically smallest cyclic rotation to standard output (stdout).

inputFormat

The input consists of a single line containing the string \( S \). The string \( S \) is non-empty and can contain up to 1000 lowercase English letters.

Input Format:

S

outputFormat

Output the lexicographically smallest cyclic rotation of the string \( S \) to standard output.

Output Format:

result
## sample
bca
abc