#C9697. Counting Distinct Gear Configurations
Counting Distinct Gear Configurations
Counting Distinct Gear Configurations
You are given a list of gear serial numbers. Each serial number is represented as a string that may include characters 'a', 'b', and 'c'. These three characters are interchangeable; that is, any permutation of the mapping among 'a', 'b', and 'c' is allowed. Two gears are considered equivalent if one can be transformed into the other by applying any permutation on the characters 'a', 'b', and 'c'.
Your task is to determine how many distinct gear configurations there are among the given serial numbers. Formally, for each gear string, consider all 6 possible substitutions (using any permutation of \(a, b, c\)) and choose the lexicographically smallest resulting string as its normalized form. Gears with the same normalized form are considered the same configuration.
Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line contains an integer n
(1 ≤ n ≤ 105), the number of gear serial numbers.
The next n
lines each contain a non-empty string representing a gear serial number. Each string consists of lowercase letters. Only the letters 'a', 'b', and 'c' are subject to permutation.
outputFormat
Output a single integer representing the number of distinct gear configurations.
## sample6
abc
bca
cab
aaa
bbb
ccc
2
</p>