Problem F
Necklace Decomposition

The set of cyclic rotations of a string are the strings
obtained by embedding the string clockwise on a ring, with the
first character following on the last, starting at any
character position and moving clockwise on the ring until the
character preceeding the starting character is reached. A
string is a necklace if it is the lexicographically smallest
among all its cyclic rotations. For instance, for the string
Any string
The relation
Input
On the first line of the input is a single positive integer
Output
For each scenario, output one line containing the necklace decomposition of the string. The necklaces should be written as ‘(’ necklace ‘)’.
Sample Input 1 | Sample Output 1 |
---|---|
5 0 0101 0001 0010 11101111011 |
(0) (0101) (0001) (001)(0) (111)(01111)(011) |