#P1808. Grouping Words by Letter Frequency
Grouping Words by Letter Frequency
Grouping Words by Letter Frequency
Oliver has decided to improve his English by memorizing words. However, he found memorizing a jumble of words to be difficult. Consequently, he decided to categorize the words.
Two words belong to the same category if and only if the number of each letter in the two words is identical. In other words, for two words \(w_1\) and \(w_2\), they can be grouped together if for every letter \(L\), the count satisfies \[ \text{count}_{w_1}(L) = \text{count}_{w_2}(L) \]
For example, the word AABAC
and CBAAA
are in the same group, while AAABB
is not in the same group as AABAC
.
You are given N words, each consisting solely of uppercase letters and having a length of at most 100. Determine into how many distinct groups these words can be classified.
inputFormat
The first line contains a single integer N — the number of words. The following N lines each contain one word consisting of uppercase letters only.
outputFormat
Output a single integer representing the number of distinct groups.
sample
5
AABAC
CBAAA
AAABB
XYZ
ZYX
3
</p>