#C4555. Unique Necklaces
Unique Necklaces
Unique Necklaces
Given an integer n and n strings representing necklaces, each necklace is a sequence of characters that can be cyclically rotated. Two necklaces are considered the same if one can be rotated to become the other. Your task is to count the number of unique necklaces (taking cyclic rotations into account).
More formally, let ( s ) be a string. A cyclic rotation of ( s ) is any string of the form ( s[i:] + s[:i] ) for ( 0 \le i < |s| ). Two strings are equivalent if one is a cyclic rotation of the other. Count how many distinct equivalence classes are present among the given necklaces.
Note: All rotations should be considered using lexicographically smallest representation (canonical form). Use LaTeX format for any mathematical expressions.
inputFormat
The input is given via standard input (stdin). The first line contains an integer ( n ) denoting the number of necklaces. The following ( n ) lines each contain a non-empty string representing a necklace.
outputFormat
Output via standard output (stdout) a single integer representing the number of unique necklaces (based on cyclic rotations).## sample
5
abc
bca
cab
xyz
yyy
3
</p>