#C3404. Count Anagram Groups

    ID: 46828 Type: Default 1000ms 256MiB

Count Anagram Groups

Count Anagram Groups

You are given a list of n words. Two words are anagrams of each other if by sorting their letters, they result in the same string. For example, listen and silent are anagrams because both become eilnst when sorted.

Your task is to count the number of distinct anagram groups in the list. Formally, for each word \( S \), let its canonical form be \( S' \), which is obtained by sorting the characters of \( S \). The answer is the number of distinct values among all \( S' \).

Read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains an integer \( n \) — the number of words.
  • The second line contains \( n \) words separated by spaces.

If \( n = 0 \), the second line may be empty.

outputFormat

Output a single integer representing the number of distinct anagram groups.

Formally, if \( G \) is the set of unique canonical forms, output \( |G| \).

## sample
4
listen silent enlist tinsel
1