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 Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

implicit none
integer :: n,i,j,k,ans
character(10) :: s
integer(16),allocatable :: p(:)
logical :: flg

read *,n
allocate(p(n))

p(:) = 0
do i = 1,n
   read *,s
   flg = .true.
   do j = 2, 10
      if (s(j:j) /= s(1:1)) then
         flg = .false.
         exit
      endif
   enddo
   if (flg) then
      p(i) = 1
   endif
   do j = 1, 10
      if (s(j:j) == 'a') then 
         k = 1
      else if (s(j:j) == 'b') then 
         k = 2
      else if (s(j:j) == 'c') then 
         k = 3
      else if (s(j:j) == 'd') then 
         k = 4
      else if (s(j:j) == 'e') then 
         k = 5
      else if (s(j:j) == 'f') then 
         k = 6
      else if (s(j:j) == 'g') then 
         k = 7
      else if (s(j:j) == 'h') then 
         k = 8
      else if (s(j:j) == 'i') then 
         k = 9
      else if (s(j:j) == 'j') then 
         k = 10
      else if (s(j:j) == 'k') then 
         k = 11
      else if (s(j:j) == 'l') then 
         k = 12
      else if (s(j:j) == 'm') then 
         k = 13
      else if (s(j:j) == 'n') then 
         k = 14
      else if (s(j:j) == 'o') then 
         k = 15
      else if (s(j:j) == 'p') then 
         k = 16
      else if (s(j:j) == 'q') then 
         k = 17
      else if (s(j:j) == 'r') then 
         k = 18
      else if (s(j:j) == 's') then 
         k = 19
      else if (s(j:j) == 't') then 
         k = 20
      else if (s(j:j) == 'u') then 
         k = 21
      else if (s(j:j) == 'v') then 
         k = 22
      else if (s(j:j) == 'w') then 
         k = 23
      else if (s(j:j) == 'x') then 
         k = 24
      else if (s(j:j) == 'y') then 
         k = 25
      else if (s(j:j) == 'z') then 
         k = 26
      endif
      p(i) = p(i) + 10**k
   enddo
enddo

call cs11(n,p)

ans = 0
do i = 1, n-1
   do j = i+1, n
      if (p(i) == p(j)) then
         ans = ans + 1
      else
         exit
      endif
   enddo
enddo

print '(i0)',ans

contains

subroutine cs11(Ncomb,a)
   integer, intent(in) :: Ncomb
   integer(16), intent(inout) :: a(Ncomb)
   integer(16) :: icomb, jcomb,rswp
   logical :: flg_swp

   icomb = Ncomb
   flg_swp = .false.
   do while (icomb > 1 .or. flg_swp)
      icomb = (icomb * 10) / 13
      if (icomb < 1) then
         icomb = 1
      else if (icomb == 9 .or. icomb == 10) then 
         icomb = 11
      endif
      flg_swp = .false.
      do jcomb = 1, Ncomb-icomb
         if (a(jcomb) > a(jcomb+icomb)) then
            rswp = a(jcomb) 
            a(jcomb) = a(jcomb+icomb)
            a(jcomb+icomb) = rswp
            flg_swp = .true.
         endif
      enddo
   enddo
endsubroutine cs11
end