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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
#define rep(i, end) for (long long int i=0; i<end; i++)
#define repp(i, begin, end) for (long long int i=begin; i<end; i+)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<__LINE__<<")"<<endl;}
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long int>;
using vllvll = vector<vll>;
using vs = vector<string>;
ll sm(vll x) {ll sum=0; rep(i, x.size()) sum+=x[i]; return sum;}
//=======================================================================================================
 
bool MOD_USE = false;
const long long MOD = 1e9 + 7;
 
long long facto(long long n)
{
    long long pro = 1;
    for(long long i=2; i<=n; ++i) {
        pro *= i;
        if(MOD_USE)
            pro %= MOD;
    }
    return pro % MOD;
}
 
long long my_pow(long long b, long long e)
{
    long long pro = 1;
    while(e != 0) {
        if(e%2 == 0) {  //even
            b *= b;
            e /= 2;
        }
        else {           //odd
            pro *= b;
            e -= 1;
        }
        b %= MOD;
        pro %= MOD;
    }
    return pro % MOD;
}
 
long long comb(long long n, long long k)
{
    if(!MOD_USE)
        return facto(n) / facto(k) / facto(n-k);
 
    else {
        long long kpw = my_pow(facto(k), MOD-2);
        deb(kpw);
        kpw %= MOD;
        long long nkpw = my_pow(facto(n-k), MOD-2);
        deb(nkpw);
        nkpw %= MOD;
        long long res = facto(n) * kpw;
        res *= nkpw;
        return res % MOD;
    }
}
 
ll all_atoi(string s)
{
    ll n = 0;
    rep(i,10) {
        n += (long long)s[i];
        if(i<9) n += 3* (s[i+1] - s[i]);
    }
    return n;
}
int main()
{
    ll n;
    cin >> n;
    vs ss(n);
    rep(i,n) cin >> ss[i];
    rep(i,n) srt(ss[i]);
    vll x(n);
    rep(i,n) x[i] = all_atoi(ss[i]);
 
    srt(x);
//vdeb(x);
    ll sum = 0;;
    ll cnt = 0;
    ll val = x[0];
    ll i = 0;
 
    vll y(100005);
    rep(i,n) {
        if(x[i] == val) cnt++;
        else if(x[i] != val) {
            y.push_back(cnt);
            cnt = 0;
            val = x[i];
        }
    }
    if(x[n-1] == val) cnt++;
    y.push_back(cnt);
    //vdeb(y);
 
 
    rep(i,y.size()) {
        sum += comb(y[i], 2);
    }
    cout << sum << endl;
}