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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        //int n = Utils.ReadInts()[0];
        //string[] s = Utils.ReadStrings(n);

        int n = 5;
        string[] s = new string[n];
        s[0] = "abaaaaaaaa";
        s[1] = "oneplustwo";
        s[2] = "aaaaaaaaba";
        s[3] = "twoplusone";
        s[4] = "aaaabaaaaa";

        List<int[]> cntList = new List<int[]>();

        for(int i = 0; i < s.Length; i++)
        {
            char[] istr = s[i].ToArray();
            int iLen = s[i].Length;
            for (int j = 0; j < s.Length; j++)
            {
                if (i == j) continue;
                int jLen = s[j].Length;
                if (iLen != jLen) continue;
                char[] jstr = s[j].ToArray();

                for(int k = 0; k < istr.Length; k++)
                {
                    int index = Utils.FindFirstIndex<char>(jstr, a => a == istr[k], 0);
                    if (index < 0) break;
                    jstr[index] = '-';
                }
                if(jstr.Min()=='-' && jstr.Max() == '-')
                {
                    int[] addInt = { i, j };
                    Array.Sort(addInt, IntComparetor.Instance);
                    if(!cntList.Exists(a => a[0]== addInt[0] && a[1] == addInt[1]))
                    {
                        cntList.Add(addInt);
                    }
                }
            }
        }
        Utils.Return(cntList.Count());
    }
    private static int Solve(int a, int b )
    {
        List<int> list = new List<int>() { a + b, a - b, a * b };
        return list.Max();
    }
}

static class Utils
{
    /// <summary>
    /// int入力を取得する
    /// </summary>
    /// <returns></returns>
    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    /// <summary>
    /// 最初に条件ヒットした配列のindexを取得する
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source"></param>
    /// <param name="func"></param>
    /// <param name="start"></param>
    /// <returns></returns>
    public static int FindFirstIndex<T>(IList<T> source, Func<T, bool> func, int start)
    {
        for(int i = start; i < source.Count; i++)
        {
            if (func(source[i]))
            {
                return i;
            }
        }
        return -1;
    }
    /// <summary>
    /// Yes or Noの文字列を返却する
    /// </summary>
    /// <param name="result"></param>
    public static void ReturnYesOrNo(bool result)
    {
        Console.WriteLine(result ? "Yes" : "No");
        Console.ReadLine();
    }

    internal static void Return(object result)
    {
        Console.WriteLine(result);
    }
    /// <summary>
    /// コンソール入力を指定回数受け取る
    /// </summary>
    /// <param name="n"></param>
    /// <returns></returns>
    internal static string[] ReadStrings(int n)
    {
        string[] result = new string[n];
        for(int i = 0; i < n; i++)
        {
            result[i] = Console.ReadLine();
        }
        return result;
    }
}
/// <summary>
/// ソートクラス
/// </summary>
class IntDisComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntDisComparetor();
    private IntDisComparetor() { }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(y, x);
    }
}
/// <summary>
/// ソートクラス
/// </summary>
class IntComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntComparetor();
    private IntComparetor() { }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(x, y);
    }
}