#K69142. Unique Rotational String Groups

    ID: 33021 Type: Default 1000ms 256MiB

Unique Rotational String Groups

Unique Rotational String Groups

You are given a list of strings. Two strings are considered equivalent if one can be obtained from the other by a cyclic rotation. Formally, for a string \( s \) of length \( L \), any string of the form s[i:] + s[:i] for \( 0 \le i < L \) is a rotation of \( s \). The canonical (or normalized) form of a string is defined to be the lexicographically smallest string among all its rotations. Your task is to determine the number of unique groups of strings, where two strings belong to the same group if their canonical forms are identical.

Example: For the strings "abc", "bca", and "cab", each string has rotations: "abc", "bca", "cab". The normalized form for all is "abc". Thus, these three strings belong to the same group.

inputFormat

The first line of input contains a single integer \( N \) indicating the number of strings. Each of the following \( N \) lines contains one non-empty string comprised of lowercase English letters.

outputFormat

Output a single integer representing the number of unique groups of equivalent strings based on cyclic rotations.

## sample
5
abc
bca
cab
xyz
yzx
2