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 (Python):
n = int(input())

s = ["".join(sorted(input())) for i in range(n)]
func = [0 for i in range(n)]

for i in range(n):
    if i == 0:
        continue
    func[i] = func[i - 1] + i

counts = {}

for ss in s:
    if ss in counts:
        counts[ss] += 1
    else:
        counts[ss] = 1

count = 0
for v in counts.values():
    count += func[v - 1]

print(count)

Solution (Python):
from collections import Counter
import numpy as np
n = int(input())
ll = []
ans = 0
for _ in range(n):
    c = list(input())
    c.sort()
    ll.append("".join(c))
ans = np.sum([np.arange(v).sum() for v in Counter(ll).values() if v > 1])
print(int(ans))

Solution (Python):
N = int(input())
counts = {}
for _ in range(N):
  s = input()
  s = ''.join(sorted(s))
  counts[s] = counts.get(s, 0) + 1
ans = 0
for c in counts.values():
  ans += c * (c-1) // 2
print(ans)

Solution (Python):

import collections

N = int(input())
string_list = [input() for i in range(N)]
L = []

for i in range(N):
  L.append("".join(sorted(string_list[i])))
  
count = collections.Counter(L)
answer = 0  

for key in count:
  if count[key] > 1:
    var_a = range(1, int(count[key]))
    var_b = sum(var_a)
    answer += var_b

print(answer)

Solution (Python):
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())

B = []
for i in range(N):
    s = input()
    s_sort = sorted(s)
    s_cnt= dict(collections.Counter(s_sort))
    l = ""
    for k,v in s_cnt.items():
        l += str(k)+str(v)
    B.append(l)


B_cnt = dict(collections.Counter(B))
D = [v for v in B_cnt.values() if v != 0]

E = [cmb(d,2) for d in D if d != 1]

print(sum(E))

Solution (Python):
n = int(input())
s = []
for i in range(n):
    a = list(input())
    a.sort()
    s.append(a)
s.sort()
s = [''.join(x) for x in s]
result = 0
j = 0
while j < n-1:
    i = 1
    count = 0
    while s[j] == s[j+i]:
        i += 1
        count += 1
        if j+i > n-1:
            break
    result += count*(count+1)/2
    j += i
print(int(result))

Solution (Python):
n=int(input())  
s=[]
cnt=0
for i in range(n):
    s.append(''.join(sorted(input())))

ss=sorted(s)

renzoku=0
for k in range(len(ss)-1):
    
    if ss[k]==ss[k+1]:
        renzoku+=1
    else:
        cnt+= (renzoku+1)*(renzoku)//2
        
        renzoku=0

cnt+= (renzoku+1)*(renzoku)//2
print(cnt)

Solution (Python):
import sys
from pprint import pprint

nCr_memo = {}

def solve(n, s):
  count_list = []
  

  alpha2num = lambda c: ord(c) - ord('a')
  count = {}
  count_str_set = set()

  for i in xrange(n):
    
    count_list.append([0] * 26)
    for s_i in xrange(10):
      
      pos = alpha2num(s[i][s_i])
      count_list[i][pos] += 1
      
    
    
    count_str = "".join(map(str, count_list[i]))
    
    if count_str in count_str_set:
      count[count_str] += 1
    else:
      count_str_set.add(count_str)
      count[count_str] = 1

  ans = 0
  for count_str, c in count.items():
    if c == 1:
      continue
    ans += nCr(c, 2)

  return ans


def nCr(n, r): 
    key = str(n) + '_' + str(r)
    if key in nCr_memo:
        return nCr_memo[key]

    a = 1 
    b = 1 
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)

    nCr_memo[key] = a / b
    return nCr_memo[key]
  

if __name__ == '__main__':

  n = int(sys.stdin.readline().strip())
  s = []
  for _ in xrange(n):
    s.append(sys.stdin.readline().strip())
  print solve(n, s)

Solution (Python):
N = int(input())
s = []
for i in range(N):
    s.append(''.join(sorted(input())))

sortedS = sorted(s)
i = 1
isSame = False
count = []
tmpS = sortedS[0]
while i < N:
    if isSame:
        if sortedS[i] == tmpS:
            count[-1] += 1
        else:
            isSame = False
            tmpS = sortedS[i]
    else:
        if sortedS[i] == tmpS:
            count.append(2)
            isSame = True
        else:
            tmpS = sortedS[i]
    i += 1

output = 0
for i in range(len(count)):
    output += count[i]*(count[i]-1)/2
print(int(output))

Solution (Python):
import collections
import math

n = int(input())
s = [input() for i in range(n)]
for i in range(n):
	s[i] = ''.join(list(sorted(s[i])))
c = collections.Counter(s)
t = 0
for v in c.values():
	if v>1:
		t += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
	else:
		continue
print(t)

Solution (Python):
n = int(input())
arr = []
for i in range(n):
  arr.append("".join(sorted(input())))
arr1 = sorted(arr)
count = 0
b1 = arr1[0]
l = []
for i in range(n-1):
  b2 = arr1[i+1]
  if b2 == b1:
    count += 1
    if i == n-2:
      l.append(count)
  else:
    l.append(count)
    count = 0
  b1 = b2
sums = 0
for j in l:
  for k in range(1,j+1):
    sums += k
print(sums)

Solution (Python):
n = int(input())

s = []
for i in range(n):
    s.append("".join(sorted(input())))
s.sort()

a = 0
r = 0
i = 1
l = len(s)
while i < l:
    if s[i] == s[i-1]:
        r = r+1
    else:
        a = a + sum(range(r+1))
        r = 0
    i = i+1

if r > 0: a = a + sum(range(r+1))
print(a)

Solution (Python):
import math

n = int(input())
word_list = []
for _ in range(n):
    word_list.append(str(input()))
for i, word in enumerate(word_list):
    
    word_list[i] = ''.join(sorted(word))

word_list = sorted(word_list)+['']
temp_str = ''
temp_count = 1
result_count = 0
for word in word_list:
    if temp_str == word:
        temp_count += 1
    else:
        if temp_count > 1:
            
            result_count += math.factorial(temp_count) // (math.factorial(temp_count - 2) * 2)
        temp_count = 1
    temp_str = word
print(result_count)

Solution (Python):
import math

N = int(input())
S = []
for i in range(N):
  S.append(''.join(sorted(input())))

from collections import Counter
Sc = Counter(S)

def com(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0
for i in Sc.values():
  if i >= 2:
    cnt += com(i,2)
  
print (cnt)

Solution (Python):
from collections import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
s = []
for i in range(n):
    m = list(input())
    m.sort()
    s.append(m)
s.sort()


count = 0
ren = 1
r = []
rsum = [0] * n
for i in range(n-1):
    if s[i] == s[i+1]:
        count += 1
        ren += 1
        
        rsum[i+1] +=rsum[i]+1
    else:
        r.append(ren)
        ren = 1
        
r.append(ren)
        
for i in range(n):
    rsum[i] = rsum[i] + 1
    

def P(n, r):
    return factorial(n)//factorial(n-r)

def C(n, r):
    return P(n, r)//factorial(r)




b = []
rsum.append(1)

for i in range(n):
    if rsum[i]>rsum[i+1]:
        b.append(rsum[i])
    
    
    
    

count2 = 0
for i in b:
    
    
    count2 += C(i, 2)
print(count2)

Solution (Python):
N = int(input())
S = [list(input()) for i in range(N)]

for i in range(N):
    S[i] = sorted(S[i])

S = sorted(S)
count = 0

a = [1]
for i in range(N-1):
    if S[i] == S[i+1]:
        a[-1] += 1
    else:
        a.append(1)
    
for i in range(len(a)):
    count += a[i]*(a[i]-1)/2
        
count = int(count)
        
print(count)

Solution (Python):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

num = int(input())
s = {}
for i in range(0,num):
	clist = [c for c in input()]
	clist.sort()
	string = ''.join(clist)
	if string in s.keys():
		s[string] += 1
	else:
		s[string] = 1

ans = 0
for key in s:
	if not s[key] == 1:
		ans += combinations_count(s[key], 2)
print(ans)

Solution (Python):
N = int(input())
li = []
ans = 0
count = 1
for i in range(N):
    s = list(str(input()))
    s.sort()
    li += [s]
li.sort()
li += ["a"]
for j in range(N):
    if li[j]==li[j+1]:
        count += 1
    else:
        ans += (count*(count-1))//2
        count = 1
print(ans)

Solution (Python):
N = int(input())
dic = {}
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(si))
    if sortedSi in dic:
        dic[sortedSi] += 1
    else:
        dic[sortedSi] = 1

for val in dic.values():
    ans += val * (val - 1) // 2

print(ans)

Solution (Python):
N = int(input())
s = []
for i in range(N):
    p = list(input())
    p.sort()
    q = "".join(p)
    s.append(q)

cnt = 0
s = sorted(s)
seq = 1
prek = s[0] 
for k in range(1, N):
    if prek == s[k]:
        seq += 1
    else:
        cnt += seq*(seq-1)/2
        seq = 1

    prek = s[k]

cnt += seq*(seq-1)/2


print(int(cnt))

Solution (Python):
n = int(input())
d = {}
count = 0
for i in range(n):
    sli = sorted(list(input()))
    s = "".join(sli)
    if s in d:
        count += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(count)

Solution (Python):
import heapq

N = int(input())

q = []

for _ in range(N):
    s = input()
    ss = sorted(s)
    heapq.heappush(q, ss)



n = 1
last = ''
ans = 0

while q:
    v = heapq.heappop(q)
    if v == last:
        n += 1
    else:
       ans += n*(n-1) // 2
       n =1

    last = v

if n != 0:
    ans += n*(n-1) // 2
    

print(ans)

Solution (Python):
N = int(input())
s = []
for _ in range(N) :
    s.append(input())

countDic = {}

for i in range(N) :
    dic = {}
    for ss in s[i] :
        if ss in dic :
            dic[ss] += 1
        else :
            dic[ss] = 1
    sortedS = ''.join(sorted(list(s[i])))
    
    if sortedS in countDic :
        countDic[sortedS] += 1
    else :
        countDic[sortedS] = 1

ans = 0

for k in countDic :
    number = countDic[k] - 1
    ans += number * (number + 1) // 2


print(ans)

Solution (Python):
import collections
from math import ceil
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
x = []
for i in range(n):
	s = list(input())
	s.sort()
	z = (' '.join(map(str, s)))
	x.append(z)
c = collections.Counter(x)

ans = 0
for y in c.values():
	if y > 1:
		ans += combinations_count(y,2)
print(ans)

Solution (Python):
from fractions import Fraction


def comb(n: int, k: int) -> int:
    if n < 0 or k < 0:
        pdt = 0
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)

    return pdt.numerator


N = int(input())

dic = {}
for i in range(N):
    s = sorted(input())
    s = "".join(s)
    dic.setdefault(s, 0)
    dic[s] += 1

ans = 0
for value in dic.values():
    ans += comb(value, 2)
print(ans)

Solution (Python):
N = int(input())
st = {}
for i in range(N):
    S = list(input())
    S.sort()
    w = "".join(S)
    if w in st:
        st[w] += 1
    else:
        st[w] = 1
ans = 0
for v in st.values():
    if v > 1:
        ans += (v * (v - 1) // 2)

print(ans)

Solution (Python):
N = int(input())
S = {}
for n in range(N):
  s = [ss for ss in input()]
  s.sort()
  s_join = "".join(s)
  if s_join not in S.keys():
    S[s_join] = 1
  else: 
    S[s_join] += 1

ans = 0
for k in S.values():
  if k == 1:
    continue
  else:
    ans += sum(range(1, k))

print(ans)

Solution (Python):
import collections

n =int(input())
X = [list(map(str, ''.join(sorted(input())))) for i in range(n)]
for i in range(n):
    X[i] = ''.join(X[i])
c = collections.Counter(X)
result = 0
for k in c.keys():
    if c[k] >= 2:
        res = 0
        for i in range(c[k]):
            res += i
        result += res
print(result)

Solution (Python):
N = int(input())

texts = {}

for i in range(N):
  text = list(input())
  text.sort()
  text = "".join(text)
  if text not in texts:
    texts[text] = 1
  else:
    texts[text] += 1

print(sum(i * (i - 1) // 2 for i in texts.values()))

Solution (Python):
from itertools import combinations

N = int(input())
li = []
cnt = 1
calc = 0

def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

for i in range(N):
    s = list(input())
    s.sort()
    li.append(s)

li.sort()
li.append('XXXX')

for i in range(0, N):
    if li[i] == li[i+1]:
        cnt += 1
    else:
        if cnt == 1:
            continue
        calc += nCr(cnt, 2)
        cnt = 1

print(calc)

Solution (Python):
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())

ss = []
for i in range(n):
	s = list(input())
	s.sort()
	ss.append("".join(s))

cs = collections.Counter(ss)
l = list(cs.values())
l.sort(reverse=True)

c = 0
for i in l:
	if i > 1:
		c+= cmb(i,2)
	elif i == 1:
		print(int(c))
		exit()
print(int(c))

Solution (Python):
import sys
import collections

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]
    c = collections.Counter(sl)

    dict = collections.defaultdict(int)
    for v in c.values():
        if v == 1:
            continue

        dict[v] += 1

    ans = 0
    for k, v in dict.items():
        ans += sum([i for i in range(k)]) * v

    print(ans)

Solution (Python):
N = int(input())
L = ["".join(sorted(list(input()))) for i in range(N)]
D = {}
for s in L :
    if s not in D :
        D[s] = 1
    else :
        D[s] +=  1
ans = 0
for k in D :
    n = D[k]
    ans += n*(n-1)//2
print(ans)

Solution (Python):


N = int(input())

dict = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s in dict:
        dict[s] += 1
    else:
        dict[s] = 1


sum = 0
list1 = list(dict.values())
for i in list1:
    sum += int(i * (i-1) / 2)

print(sum)

Solution (Python):
import sys
from collections import Counter
from math import factorial
import numpy as np
from scipy.misc import comb
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    
    c = Counter(S)
    mosc = c.most_common()
    
    ans = np.int64(0)
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          
          ans +=  comb(n, r, exact=True)
    print(ans)
 
if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N = int(input())
dic = defaultdict(int)
for i in range(N):
    s = input()
    cnt = [0] * 26
    for c in s:
        cnt[ord(c)-97] += 1
    dic[tuple(cnt)] += 1
ans = 0
for key in dic:
    if dic[key] > 1:
        ans += Com(dic[key], 2)
print(ans)

Solution (Python):
from collections import defaultdict
from collections import Counter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

cnt_dic = defaultdict(lambda: 0)

for _ in range(n):
    s = list(input())
    cnt_s = [0] * 52
    for c in s:
        cnt_s[ord(c)- ord('a')] += 1
    cnt_dic[tuple(cnt_s)] +=1

ans = 0
for i in cnt_dic.values():
    if 1 < i:
        ans += combinations_count(i,2)

print(ans)

Solution (Python):
N = int(input())
d = dict()

for i in range(N):
    s = tuple(sorted(input()))
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1

ans = 0
for i in d.values():
    if i != 1:
        ans += i * (i - 1) // 2

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
ls=[]
ans=0
for i in range(n):
    s=list(input())
    s.sort()
    ls.append("".join(s))
c=Counter(ls)
for i in c.values():
    if i>1:
        ans+=i*(i-1)//2
print(ans)

Solution (Python):
dic = {}
ans = 0
N = int(input())
for i in range(N):
    x = sorted(input())
    x = "".join(x)
    if x in dic:
        dic[x] += 1
    else:
        dic[x] = 1

for i in dic:
    x = dic[i]
    if x > 1:
        ans += x*(x-1) // 2
print(ans)

Solution (Python):
N = int(input())
lis = ["".join(sorted(input())) for _ in range(N)]
lis.sort()

count = 0
while len(lis) != 0:
  p = lis.pop()
  i = 1
  while len(lis) > 0:
    if lis[-1] == p:
      count += i
      lis.pop()
      i += 1
    else:
      break
print(count)

Solution (Python):
from collections import Counter

N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
c = Counter(sorted(s))
ret = int(sum([x * (x-1) / 2 for x in c.values()]))
print(ret)

Solution (Python):
import collections
count = 0
N = int(input())
candidates = []
for i in range(N):
    candidates.append("".join(sorted(input())))
new = set(candidates)
a = collections.Counter(candidates)
for j in a.values():
    if j == 2:
        count += 1
    elif j != 1:
        count += int(j*(j-1)/2)
print(count)

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7
from collections import Counter

def main():
    N = INT()
    S = []
    for _ in range(N):
        tmp = Counter(input())
        S_tmp = ''
        for i in sorted(tmp.keys()):
            S_tmp += i + str(tmp[i])
        S.append(S_tmp)
    
    count = Counter(S)
    ans = 0
    for i in count.values():
        if i > 1:
            ans += i * (i - 1) / 2
    print(int(ans))

if __name__ == '__main__':
    main()

Solution (Python):
from operator import mul
import sys
from functools import reduce

def cmb(n,r):
    if n == 1:
        return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


from collections import defaultdict
d = defaultdict(int)

N = int(input())
s = list(list(input()) for i in range(N))

for i in range(N):
    s[i] = sorted(s[i])

s.sort()

temp = ""


for i in s:
    temp = ''.join(i)
    d[temp] += 1

box = list(d.values())

ans = 0
for j in box:
    ans += cmb(j, 2)

print(ans)

Solution (Python):

import numpy as np
import math
import copy
import re
import sys


inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)


def gcd(a, b): 
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): 
  return a * b // gcd (a, b)

def gcd3(lis): 
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): 
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): 
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1


"""
n = int(input())


a = map(int, input().split())
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())


a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""


"""
a = sorted(a)
a = sorted(a, reverse=True)

"""


"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   
    print res.start()   
    print res.end()     
    print res.span()    
"""

def strnum(st):
  st = list(st)
  for i in range(len(st)):
    tmp = st[i] + str(st[i:].count(st[i]))
    st[i] = str(tmp)
  return st

def strsort(st):
  st = list(st)
  st = sorted(st)
  return "".join(st)

def kai(num):
  if num==1:
    return 1
  else:
  	return num * kai(num-1)

def choose(num):
  return int(num*(num-1)/2)
  
import collections

n = int(input())
s = [""]*n
for i in range(n):
  s[i] = strsort(input())


c = collections.Counter(s)
count=0
for v in c.values():
  count += choose(v)

print(count)

Solution (Python):
ss=[]
n=int(input())
i=0
while i!=n:

    s=list(input())
    s.sort()
    ss.append(s)
    i+=1
ans=0
i=1
ss.sort()
mians=0

s=ss[0]
while i!=n:
    if s==ss[i]:
        ans+=1
        mians+=1


    else:
        while mians!=0:
            mians-=1
            ans+=mians
    s=ss[i]
    i += 1
while mians != 0:
    mians -= 1
    ans += mians

print(ans)

Solution (Python):
import collections as c
import math as m
n=int(input())
a=[input()for i in range(n)]
a=list(map(sorted,a))
a=list(map(lambda x:"".join(x),a))
r=list(c.Counter(a).values())
r=[ m.factorial(n) // (m.factorial(n - 2) * 2) for n in r if n>1]
print(sum(r))

Solution (Python):
n = int(input())
check = {}
for i in range(n):
    s = ["w"]*10
    c = 0
    for i in input():
        s[c] = i
        c += 1
    s.sort()
    s = "".join(s)
    if s in check:
        check[s] += 1
    else:
        check[s] = 1
ans = 0
for i in check.keys():
    ans += (check[i]-1)*check[i]/2
print(int(ans))

Solution (Python):
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]

d = {i:0 for i in set(s)}
for i in s:
  d[i] += 1
  
count = 0

for i in d.values():
  count += i*(i-1)//2
  
print(count)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = _I()
S = []
for i in range(N):
    S.append(input())

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))






















chars = []
for s in S:
    char_list = []
    for char in s:
        char_list.append(char)
    char_list.sort()
    char_list = ''.join(char_list)
    chars.append(char_list)

ans = 0
done_list = []
char_counts = {}
for char in chars:
    if char in char_counts.keys():
        char_counts[char] += 1
    else:
        char_counts[char] = 1
for char_count in char_counts.values():
    if char_count == 1: continue


    ans += combinations_count(char_count, 2)
print(ans)

Solution (Python):
n = int(input())
dic = {}
for i in range(n):
    p = list(input())
    p.sort()
    p = ''.join(p)
    if p in dic.keys():
        dic[p] += 1
    else:   
        dic[p] = 1

ans = 0
for i in dic.keys():
    if dic[i] == 1:
        continue
    else:
        ans += (dic[i]*(dic[i] - 1))//2

print(ans)

Solution (Python):
from collections import Counter
from math import factorial
N=int(input())
L=[]
Lappend=L.append
ans=0
for _ in range(N):
    s=list(input())
    s.sort()
    Lappend("".join(s))
C=Counter(L)
for i in C.values():
    if i==1:pass
    elif i==2:ans+=1
    else:
        ans+=((factorial(i)//factorial(i-2))//factorial(2))
print(ans)

Solution (Python):
def calc(N, s):
    s_sorted = []
    for w in s:
        w_list = list(w)
        w_list.sort()
        s_sorted += [''.join(w_list)]
    s_sorted.sort()
    result = 0
    count = 1
    i = 1
    a = s_sorted[0]
    while (i < N):
        if (a == s_sorted[i]):
            count += 1
        else:
            result += count * (count - 1) // 2
            count = 1
            a = s_sorted[i]
        i += 1
    return result + count * (count - 1) // 2

N = int(input())
s = [input() for _ in range(N)]
print(calc(N, s))

Solution (Python):
n = int(input())
dic = {}
for _ in range(n):
  si = str(input())
  li = [si[i] for i in range(10)]
  li.sort()
  moji = "".join(li)
  if moji in dic.keys():
    dic[moji] += 1
  else:
    dic[moji] = 1
sm = 0
for j in dic.values():
  sm += j*(j-1)//2
print(sm)

Solution (Python):
import sys

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

def comb(n, k):
    if n < k:
        return 0

    m = 1
    if n < 2 * k:
        k = n - k
    for i in range(1, k + 1):
        m = m * (n - i + 1) // i    
    return m

N = INT()

s = []

for _ in range(N):
    s.append(sorted(input()))

s = sorted(s)
s.append("")

ans = 0

i = 0
while i < N:
    j = i + 1

    while s[i] == s[j]:
        j += 1

    ans += comb(j - i, 2)

    i = j

print(ans)

Solution (Python):

import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

c = collections.Counter(str)

count = 0
for k, v in c.items():
    if v > 1:
        count += combinations_count(v, 2)

print(count)

Solution (Python):

import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

c = collections.Counter(str)

count = 0
for k, v in c.items():
    if v > 1:
        count += combinations_count(v, 2)

print(count)

Solution (Python):
n = int(input())
s = []
for i in range(n):
    ss = ''.join(sorted(input()))
    s.append(ss)

from collections import Counter
d = Counter(s)

count = 0
for s in d.values():
    if s > 1:
        count += s/2*(s-1) 


print(int(count))

Solution (Python):
from collections import defaultdict

d = defaultdict(int)
c = 0

for _ in range(int(input())):
    s = list(input())
    s.sort()
    s1 = ''
    for i in s:
        s1 += i
    s = s1

    if s in d:
        c += d[s]
        d[s] += 1
    else:
        d[s] += 1

print(c)

Solution (Python):
N=int(input())
s=[]
for k in range(N):
    s.append([None]*10)
    l=input()
    for j in range(10):
        s[k][j]=l[j]
    s[k].sort()
s.sort()
a=0
r=0
for i in range(N-1):
    if s[i]==s[i+1]:
        r+=1
    elif r!=0:
        a+=r*(r+1)//2
        r=0
a+=r*(r+1)//2
print(a)

Solution (Python):

from collections import Counter
N = int(input())
ls = []
for n in range(N):
    ls.append("".join(sorted(input())))

cnt = Counter(ls)

ans = [i*(i-1)/2 for i in list(cnt.values())]
print (int(sum(ans)))

Solution (Python):
N = int(input())
S = {}

cnt = 0
for n in range(N):
    s = ''.join(sorted(input()))

    if s in S.keys():
        cnt += S[s]
        S[s] += 1
    else:
        S[s] = 1

print(cnt)

Solution (Python):
import collections

n=int(input())
prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]
num=[1] * n
count = 0
for i in range(0,n):
    S = input()
    for s in S:
        num[i] = num[i] * prime[ord(s)-97]



c = collections.Counter(num)
for v in c.values():
    if v > 1:
        count = count + v*(v-1)/2

print(int(count))

Solution (Python):
def combinations_count(all, pick=2):
    tmp_p = [x for x in range(all, all-pick, -1)]
    tmp = [x for x in range(pick, 0, -1)]
    return int(eval("*".join(map(str,tmp_p))) / eval("*".join(map(str,tmp))))

N = int(input())
s = {}
for n in range(N):
    tmp = "".join(sorted(list(input())))
    if tmp in s:
        s[tmp] = s[tmp] + 1
    else:
        s[tmp] = 0


ans = 0
for val in s.values():
    if val != 0:
        ans += combinations_count(val+1)
print(ans)

Solution (Python):
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)


def sumi(i):
	return i * (i - 1) // 2

N = int(input())
mydict = {}

for i in range(N):
	s = input()
	l = list(s)
	l.sort()
	s = ''.join(l)
	
	
	if s in mydict:
		mydict[s] += 1
	else:
		mydict[s] = 1
	

ans = 0

for i in mydict.values():
	ans += sumi(i)
	
print(ans)

Solution (Python):

n = int(input())
S = []
D = {}
count = 0
for i in range(n):
    s = ''.join(sorted(input()))
    if s in D:
        count += D[s]
        D[s] += 1
    else:
        D[s] =1
print(count)