#K78317. Anagram Pairs

    ID: 35060 Type: Default 1000ms 256MiB

Anagram Pairs

Anagram Pairs

Given a list of passwords, count the number of pairs of passwords that are anagrams of each other when compared in a case-insensitive manner. Two strings are considered anagrams if their sorted lowercase representations are identical. Mathematically, if a group of passwords forms an anagram group of size ( n_i ), then the number of distinct pairs from that group is given by ( \binom{n_i}{2} = \frac{n_i(n_i-1)}{2} ).

inputFormat

The input is read from standard input and consists of multiple lines. The first line contains an integer ( n ) representing the number of passwords. The following ( n ) lines each contain one password string.

outputFormat

Output a single integer representing the total number of pairs of passwords that are anagrams of each other (case-insensitive).## sample

4
abc
Bac
adb
BAD
2

</p>