#C12455. Anagram Pairs
Anagram Pairs
Anagram Pairs
You are given a list of words. Two words are anagrams if one can be rearranged to form the other (e.g. listen and silent). Your task is to count the number of pairs of words that are anagrams of each other.
More formally, given a list of n words \(w_1, w_2, \dots, w_n\), for every pair \((i,j)\) with \(1\leq i<j\leq n\), count the pair if \(w_i\) and \(w_j\) are anagrams. The answer is the total count of such pairs.
Note: Words consist only of lowercase letters. The number of words and their lengths are such that a solution with an efficient algorithm will run within time limits.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer n representing the number of words. Each of the following n lines contains one word.
Example:
5 listen silent enlist google gogole
outputFormat
Output a single integer to standard output (stdout) that represents the number of pairs of words that are anagrams of each other.
Example:
4## sample
5
listen
silent
enlist
google
gogole
4