#K40092. Count Anagram Pairs

    ID: 26565 Type: Default 1000ms 256MiB

Count Anagram Pairs

Count Anagram Pairs

We are given a list of words. Two words are anagrams if one word can be formed by rearranging the letters of the other.

Write a program that computes the total number of pairs of indices ( (i, j) ) such that ( i < j ) and the words at these indices are anagrams of each other. The comparison is case-sensitive, meaning that uppercase and lowercase letters are treated as distinct.

For example, the words listen and silent are anagrams because when sorted they both produce eilnst.

Input will be read from standard input (stdin) and the result should be output to standard output (stdout).

inputFormat

The first line contains an integer ( n ) which represents the number of words. The next ( n ) lines each contain one word.

outputFormat

A single integer representing the total number of pairs of words (with indices ( i < j )) that are anagrams of each other.## sample

3
cat
dog
bird
0

</p>