Problem:
Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.

Solution in C (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<stdio.h>
int main(){
  int i,j,n;
  scanf("%d",&n);
  int cnt[n+10][26];
  for(i=0;i<n;i++){ for(j=0;j<26;j++) cnt[i][j]=0; }
  char a[n+10][15];
  for(i=0;i<n;i++){
    scanf("%s",a[i]);
    for(j=0;j<10;j++){
      switch(a[i][j]){
      case 'a': cnt[i][0]+=1; break;
      case 'b': cnt[i][1]+=1; break;
      case 'c': cnt[i][2]+=1; break;
      case 'd': cnt[i][3]+=1; break;
      case 'e': cnt[i][4]+=1; break;
      case 'f': cnt[i][5]+=1; break;
      case 'g': cnt[i][6]+=1; break;
      case 'h': cnt[i][7]+=1; break;
      case 'i': cnt[i][8]+=1; break;
      case 'j': cnt[i][9]+=1; break;
      case 'k': cnt[i][10]+=1; break;
      case 'l': cnt[i][11]+=1; break;
      case 'm': cnt[i][12]+=1; break;
      case 'n': cnt[i][13]+=1; break;
      case 'o': cnt[i][14]+=1; break;
      case 'p': cnt[i][15]+=1; break;
      case 'q': cnt[i][16]+=1; break;
      case 'r': cnt[i][17]+=1; break;
      case 's': cnt[i][18]+=1; break;
      case 't': cnt[i][19]+=1; break;
      case 'u': cnt[i][20]+=1; break;
      case 'v': cnt[i][21]+=1; break;
      case 'w': cnt[i][22]+=1; break;
      case 'x': cnt[i][23]+=1; break;
      case 'y': cnt[i][24]+=1; break;
      case 'z': cnt[i][25]+=1; break;
      }
    }
  }
  long int ans=0,sum;
  int count;
  for(i=0;i<n-1;i++){
    count = i+1;
    sum = 0;
    for(j=0;j<26;j++){
      if(count==n)
        break;

      if(cnt[i][j]==cnt[count][j]){
        sum += 1;
      }else{
        count++;
        sum = 0;
        j=-1;
        continue;
      }
      if(j==25 && count<n-1){
        ans++;
        count++;
        j=-1;
        continue;
      }
    }
    if(sum==26)
      ans++;
  }
  printf("%d\n",ans);
  return 0;
}