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):
import sys
input = sys.stdin.readline

n = int(input())

ans = 0
D = {}
for i in range(n):
      s = "".join(sorted(input()))
      if s in D.keys():
            ans += D[s]
            D[s] += 1
      else:
            D[s] = 1
print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

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

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
s_list = []
for _ in range(N):
    s = ''.join(sorted(list(input())))
    s_list.append(s)

b = 0
for i in Counter(s_list).values():
  if i==1:
    pass
  else:
    b += combinations_count(i,2)
print(b)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return


def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return


def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return


def D():
    n, m = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: (x[1], x[0]), reverse=True)
    ans = 0
    for i in range(n):
        if m >= ab[i][0]:
            ans += ab[i][1]
            m -= 1
    print(ans)
    return


def E():
    return


def F():
    return


if __name__ == '__main__':
    C()

Solution (Python):
n = int(input())
ans = 0
dict = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s in dict.keys():
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)

Solution (Python):
N=int(input())
lst=[]
for i in range(N):
  text=input()
  lst.append([sorted(text)])
lst=sorted(lst)      
count=0
i=0
while(i<N-1):
  j=1
  while(lst[i]==lst[i+j]):
    count=count+j
    j=j+1
    if (i+j >= N):
      break
  i=i+j
print(count)

Solution (Python):
from collections import defaultdict

d = defaultdict(int)
n = int(input())
s = [input() for _ in range(n)]

for tmp in s:
    tmp =sorted(tmp)
    tmp = "".join(tmp)
    d[tmp] += 1

result = 0
for c in d.values():
    result += c*(c-1) // 2

print(result)

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

for i in range(N):
    s = list(input())
    s.sort()
    key = str(s)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = 0
for value in dic.values():
    ans += value*(value-1) / 2
print(int(ans))

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


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

Solution (Python):
from collections import Counter

N = int(input())
S = ["".join(sorted(list(input()))) for _ in range(N)]

cnt = Counter(S)
print(sum(v*(v-1)//2 for v in cnt.values()))

Solution (Python):
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)

Solution (Python):
def solve():
    N, *sl = map(lambda x:''.join(sorted(x)), open(0).read().split())
    dic = {}
    ans = 0
    
    for s in sl:
        if s in dic:
            ans += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    
    print(ans)


if __name__ == '__main__':
    solve()

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

result = 0
moji = {}
for i in range(N):
    val = str(sorted(str(input())))
    if (val in moji):
        moji[val].append(i)
    else:
        moji[val] = [i]

result = 0
for val in moji.values():
    result += int((len(val)*(len(val)-1))/(2))

print(result)

Solution (Python):

N = int(input())
S = []
for i in range(N):
    s = list(str(input()))
    s.sort()
    S.append(s)
S.sort()

count = 0
now = 0
nows = 0
for i in range(N):
    if i == 0:
        nows = S[0]
        now = 1
    else:
        if nows != S[i]:
            nows = S[i]
            count += ((now*(now-1))//2)
            now = 1
        else:
            now+=1
            
count += ((now*(now-1))//2)
print(count)

Solution (Python):
n = int(input())
d = {}

for _ in range(n):
    s = ''.join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

ans = 0
for k, v in d.items():
    ans += (v * (v - 1)) / 2

print(int(ans))

Solution (Python):
n = int(input())
s = {}
cnt = 0
for i in range(n):
    ss = input()
    t = []
    
    for j in ss:
        t.append(j)
    
    
    t = sorted(t)
    
    
    
    
    
    u = "".join(t)
    
    if u in s.keys():
        s[u] += 1
    else:
        s[u] = 1

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

Solution (Python):
def main():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for i in s:
        if i not in dic:
            dic[i] = 0
        else:
            dic[i] += 1
            ans += dic[i]
        
    print(ans)


if __name__ == "__main__":
    main()

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

dic = {}
count = 0
for i in range(n):
    s = list(input().strip())
    s.sort()
    s = "".join(s)
    if s not in dic:
        dic[s] = 0
    else:
        dic[s] += 1
        count += dic[s]

print(count)

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

s_dict ={}
ans = 0
for i in range(N) :
    if s[i] in s_dict.keys() :
        ans += s_dict[s[i]]
        s_dict[s[i]] += 1
    else :
        s_dict[s[i]] = 1
print(ans)

Solution (Python):
from collections import Counter
import math
N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
ans = 0
for v in Counter(S).values():
    if v>1:
        ans += math.factorial(v)/(math.factorial(2)*math.factorial(v-2))
print(int(ans))

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

s_dic = {}
ans = 0

for si in range(N):
    if s[si] in s_dic.keys():
        ans += s_dic[s[si]]
        s_dic[s[si]] += 1
    else:
        s_dic[s[si]] = 1
print(ans)

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

Sdic = {}
ans = 0

for i in range(N):
    if S[i] not in Sdic.keys():
        Sdic[S[i]] = 1
    else:
        ans += Sdic[S[i]]
        Sdic[S[i]] += 1
print(ans)

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

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom


n=int(input())
a=0
l=[''.join(list(map(str,sum(sorted(list(map(list,co(input()).items()))),[])))) for i in range(n)]
for d,s in co(l).items():
  if s>=2:a+=combinations_count(s, 2)
print(a)

Solution (Python):
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

Solution (Python):

import sys


def solve(N: int, s: "List[str]"):

    result = 0
    str_dict = dict()
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()
        s_i = "".join(s_i)

        if s_i in str_dict:
            result += str_dict[s_i]
            str_dict[s_i] += 1
        else:
            str_dict[s_i] = 1

    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    s = [next(tokens) for _ in range(N)]  
    solve(N, s)


if __name__ == "__main__":
    main()

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

dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Solution (Python):
import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Solution (Python):
import math


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

n = int(input())
ans_dict = {}

for _ in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    try:
        ans_dict[s] += 1
    except:
        ans_dict[s] = 1

ans = 0
for key in ans_dict:
    if ans_dict[key] >= 2:
        ans += combinations_count(ans_dict[key], 2)
print(ans)

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = tuple(sorted(list(s)))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) // 2
print(ans)

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

for _ in range(n):
  value = input()
  key = ''.join(sorted(value))
  
  if key in s:
    s[key] += 1
  else:
    s[key] = 1
          
sum = 0

for value in s.values():
  sum += value*(value-1)//2
  
print(sum)

Solution (Python):
n=int(input())
dicts={}
nums=0
for x in range(n):
    s=str(input())
    sorting=sorted(s)
    sorting="".join(sorting)
    if sorting not in dicts.keys():
        dicts[sorting]=1
    else:
        dicts[sorting]+=1
for x in  dicts.values():
    nums+=int(x*(x-1)/2)
print(nums)

Solution (Python):
n= int(input())
l = []
for _ in range(n):
    l.append(''.join(sorted(input())))

d = dict()
cnt = 0
for e in l:
  
  if e in d:
    
    d[e] += 1
    cnt += d[e]
    
  else:
    
    d[e] = 0
    
print(cnt)

Solution (Python):
from collections import Counter

N = int(raw_input())
s = []
for i in range(0,N):
  K = (''.join(sorted(raw_input())))
  s.append(K)
ans = 0

for i in Counter(s).values():
  if i > 1:
    for j in range(1,i):
      ans = ans + j
print ans

Solution (Python):
n = int(input())
tatelist = [input() for i in range(n)]

jlist = [sorted(tatelist[i]) for i in range(n)]
klist = ["".join(jlist[i]) for i in range(n)]

kdic = {}

count = 0
for i in range(n):
    if klist[i] in kdic.keys():
        count += kdic[klist[i]]
        kdic[klist[i]] += 1

    else:
        kdic[klist[i]] = 1

print(count)

Solution (Python):
N = int(input())
ssorted = []
for i in range(N):
    ssorted.append("".join(sorted(list(input()))))
sdict = {}
for i in ssorted:
    if i in sdict:
        sdict[i] += 1
    else:
        sdict[i] = 1
count = 0
for i in sdict:
    s = sdict[i]
    if s >= 2:
        count += s*(s-1)//2
print(count)

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

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

print(x)

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

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

count = 0
t = dict()
for i in range(N):
    if S[i] in t:
        t[S[i]] += 1
    else:
        t[S[i]] = 1
ans = 0
for key in t:
    ans += (t[key]*(t[key]-1)) // 2


print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
sorted_s_list = defaultdict(int)
count = 0
s_list = []
for _ in range(N):
    s = str(sorted(list(input())))
    if sorted_s_list[s] > 0:
        count += sorted_s_list[s]
        sorted_s_list[s] += 1
    else:
        sorted_s_list[s] = 1
print(count)

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


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


t = dict()
for i in range(N):
    if S[i] in t:
        t[S[i]] += 1
    else:
        t[S[i]] = 1

print(sum(t[key]*(t[key] - 1) // 2 for key in t))

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

Solution (Python):
n = int(input())
s = [input() for i in range(n)]


ss = ['']*n
for i in range(n):
    ss[i] = ''.join(sorted(s[i]))
    

sss = list(set(ss))


dict_ss = {}
for i in range(len(sss)):
    dict_ss[sss[i]] = 0


for i in range(n):
    dict_ss[ss[i]] += 1



ans_l = [dict_ss[sss[i]] for i in range(len(sss))]
ans = 0
for i in range(len(ans_l)):
    ans += (ans_l[i]*(ans_l[i]-1))/2

print(int(ans))

Solution (Python):
from math import factorial

def main():
    n, *s = open(0).read().split()

    exist_s = {}
    for cur_s in s:
        cur_s = ''.join(sorted(list(cur_s)))
        if cur_s in exist_s:
            exist_s[cur_s] += 1
        else:
            exist_s[cur_s] = 1

    ans = 0
    for val in exist_s.values():
        if val < 2:
            continue
        ans += factorial(val) // (factorial(val - 2) * factorial(2))

    print(ans)
    return()

if __name__ == '__main__':
    main()

Solution (Python):
import collections


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

Solution (Python):
import collections
def counter_(s):
  counter = collections.Counter(s)
  counter =  [list(e) for e in counter.items()]
  counter.sort()
  return counter

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())
S = []

for i in range(N):
  s = list(input())
  s.sort()
  str_ = ''.join(s)
  S.append(str_)

ans = 0
S_ = counter_(S)
for i in range(len(S_)):
  if(S_[i][1] != 1):
    a = cmb(S_[i][1],2)
    ans += a
print(ans)

Solution (Python):
def main():
  from collections import Counter
  from sys import stdin
  readline = stdin.readline
  N = int(readline())
  t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
  print(sum(t[k] * (t[k] - 1) // 2 for k in t))
main()

Solution (Python):
from collections import Counter
n = int(input())
t = Counter([''.join(sorted(input())) for _ in range(n)])
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Solution (Python):
from collections import Counter
n = int(input())
S = list(input() for i in range(n)) 

ctr = Counter()
ans = 0
for s in S:
    s =  ''.join(sorted(list(s)))
    if s in ctr:
        ans += ctr[s]
    ctr[s] += 1 

print(ans)

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

print(ans)

Solution (Python):
n= int(input())
l = []
for _ in range(n):
    l.append(''.join(sorted(input())))

d = dict()
cnt = 0
for e in l:
    if e in d:
        d[e] += 1
        cnt += d[e]
    else:
        d[e] = 0

print(cnt)

Solution (Python):
from collections import Counter

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

cs = Counter(s)

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

Solution (Python):
def main():
    N = int(input())
    
    S = sorted(sorted(input()) for _ in range(N))

    sol = 0
    current = 1

    for i, s in enumerate(S[1:], start=1):
        if s == S[i - 1]:
            current += 1
        else:
            sol += (current * (current - 1)) // 2
            current = 1

    sol += (current * (current - 1)) // 2
    print(sol)


if __name__ == '__main__':
    main()

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

L = []

for i in range(0,len(S)):
	L.append(sorted(S[i]))

for i in range(0,len(L)):
	L[i] = ",".join(L[i])

dicL = dict()
answer = 0

for l in L:
	if l in dicL:
		dicL[l] += 1
		answer += dicL[l]
	else:
		dicL[l] = 0
		
print(answer)

Solution (Python):
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]

D = {}
ans = 0
for s in S:
    if s in D:
        D[s] += 1
        ans += D[s]
    else:
        D[s] = 0

print(ans)

Solution (Python):
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom

def main(): 
    n = int(input())
    s = []
    dic = {}
    ans = 0
    for i in range(n):
        b = ""
        a = sorted(input())
        for j in range(len(a)):
            b += str(a[j])
        s.append(b)
        if b in dic:
            dic[str(b)] = dic[str(b)] + 1
        else:
            dic[str(b)] = 1

    for key in dic:
        if dic[key] > 1:
            ans += ncr(dic[key], 2)
    
    print(int(ans))
    

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
lst = [input() for _ in range(n)]

dic = dict()
res = 0
for i in range(n):
    sorted_string = "".join(sorted(lst[i]))
    if sorted_string in dic:
        dic[sorted_string] += 1
        res += dic[sorted_string]
    else:
        dic[sorted_string] = 0
    
print(res)

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    A=[0]*n
    for i in range(n):
        A[i]=''.join(sorted(input()))
    A.sort()
    from itertools import groupby
    ans=0
    for k,v in groupby(A):
        a=len(list(v))
        if a>=2: ans+=a*(a-1)//2
    print(ans)

resolve()

Solution (Python):
def main():

    N = int(input())
    S = {}
    cnt = 0
    for _ in range(N):
        s = list(input())
        s.sort()
        s = "".join(s)
        if s not in S:
            S[s] = 0
        else:
            S[s] += 1
            cnt += S[s]
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
b = {}
ans = 0
for _ in range(n):
  x = list(input())
  x.sort()
  x = "".join(x)
  if not x in b:
    b[x] = 0
  else:
    b[x] += 1
    ans += b[x]
print(ans)

Solution (Python):
N = int(input())
s_list = []
s_dict = {}
ans = 0

for j in range(N):
    s_list.append("".join(sorted(input())))

for i in range(N):
    if s_list[i] in s_dict.keys():
        ans += s_dict[s_list[i]]
        s_dict[s_list[i]] += 1

    else:
        s_dict[s_list[i]] = 1

print(ans)

Solution (Python):


n=int(input())




s=[list(input())for _ in range(n)]







ans=[]
dic={}
cnt=0

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


for i in range(n):
    if not ans[i]  in dic:
        dic[ans[i]]=1
    else:
        dic[ans[i]]+=1

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
strings = [[]*10 for i in range(n)]
for i in range(n):
    strings[i] = sorted(list(input()))

strings = sorted(strings)

succession = [0]*n
counter = 0
for i in range(1,n):
    if strings[i] == strings[i-1]:
        succession[i] = succession[i-1]+1
    if strings[i] != strings[i-1] and succession[i-1]>0:
        counter += (succession[i-1]+1)*succession[i-1]//2
    if i == n-1 and succession[i] >0:
        counter += (succession[i]+1)*succession[i]//2

print(counter)

Solution (Python):
from collections import defaultdict
N = int(input())
S = defaultdict(int)
for i in range(N):
    S[''.join(sorted(input()))] += 1
print(sum([v * (v - 1) // 2 for v in S.values()]))

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

strings = {}

ans = 0

for _ in range(N):
    s = sorted(list(input()))
    join_s = ''.join(s)
    if join_s in strings:
        strings[join_s] += 1
        ans += strings[join_s]
    else:
        strings[join_s] = 0

print(ans)

Solution (Python):

n=int(input())
s=[]
for i in range(n):
    f=list(input())
    f.sort()
    s.append(f)
s.sort()
k=0
a=1
t=0
for i in range(1,n):
    if s[k]==s[i]:
        a+=1
    else:
        t=t+(a*(a-1))//2
        a=1
        k=i
if s[n-1]==s[k]:
    t=t+(a*(a-1))//2
print(t)

Solution (Python):
n=int(input())
s=[list(input()) for _ in range(n)]
dic={}
t=[0]*n
for i in range(n):
	s[i].sort()
	t[i]=str(s[i])
for i in range(n):
	if t[i] in dic:
		dic[t[i]]+=1
	else:
		dic[t[i]]=1
counts=list(dic.values())
count=0
for i in range(len(counts)):
	count+=(counts[i])*(counts[i]-1)/2
print(int(count))

Solution (Python):
from collections import Counter
import sys
n = int(sys.stdin.readline())
L = [''.join(sorted(sys.stdin.readline().strip())) for _ in range(n)]
ans = 0
L = Counter(L)
for num in L.values():
    ans += num*(num-1)//2
print(ans)

Solution (Python):
n=int(input())
d={}
count=0
for i in range(n):
    s=tuple(sorted(input()))
    if s not in d:
        d[s]=0
    count+=d[s]
    d[s]+=1
print(count)

Solution (Python):
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    
    if a in ctr:
        answer += ctr[a]
    ctr[a] += 1
print(answer)

Solution (Python):
N=int(input())
l=[]
d={}
ans=0
for i in range(N):
  s=list(str(input()))
  s.sort()
  l.append(s) 
for s in l:
  s=''.join(s)
  if s in d:
    ans+=d[s]
    d[s]+=1
  else:
    d[s]=1
print(ans)

Solution (Python):
N = int(input())
words = []
dic = {}
count = 0

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

for word in words:
    if word in dic:
        count += dic[word]
        dic[word] += 1
    else:
        dic[word] = 1

print(count)

Solution (Python):
from collections import defaultdict
from math import factorial

n = int(input())
s = []

for i in range(n):
    t = list(input())
    t.sort()
    s += [t]

for i in range(n):
    s[i] = ",".join(s[i])
    s[i] = s[i].replace(",","")
    
ans = 0

d = defaultdict(int)

for key in s:
    if key in d:
        ans += d[key]
    d[key] += 1
    
print(ans)

Solution (Python):
N = int(input())
L= []
for _ in range(N):
    l = sorted(list(input()))
    tmp = ''
    for x in l:
        tmp += x
    L.append(tmp)
L = sorted(L)

def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)

def comb_cal(x):
    return x * (x - 1) / 2
ans = 0
for x in c:
    ans += comb_cal(x[1])
print(int(ans))

Solution (Python):
from math import factorial
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())
D = {}
L = [[]for _ in range(N)]
count = 0
for i in range(N):
    L[i] = list(input())
    L[i].sort()
    L[i] = tuple(L[i])
    if L[i] in D:
        D[L[i]] = D[L[i]] + 1
        if D[L[i]] == 2:
            D[L[i]] = D[L[i]] + 1
    else:
        D[L[i]] = 0
for key in D:
    if D[key] > 2:
        count += cmb(D[key],2)
    else:
        count += D[key]

print(count)

Solution (Python):
import collections
N = int(input())
d = {}
ans = 0
for i in range(N):
    l = ' '.join(sorted(input()))
    if l in d:
        ans += d[l]
        d[l] += 1
    else:
        d[l] = 1
print(ans)

Solution (Python):
n = int(input())
S = []
dic = {}
count = 0

for i in range(n):
    S.append(str(sorted(input())))
    
for Sstr in S:
    if Sstr in dic:
        count += dic[Sstr]
        dic[Sstr] += 1
    else:
        dic[Sstr] = 1
        

print(count)

Solution (Python):
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(str(sorted(input())))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

Solution (Python):
n = int(input())
dict = {}
ans = 0

for i in range(n):
  s = str(sorted(input()))
  if s in dict.keys():
    ans += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(ans)

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

cnt = 0
dic = {}

for w in S:
    if w in dic:
        cnt += dic[w]
        dic[w] += 1
    else:
        dic[w] = 1
        
print(cnt)

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

map = {}
count = 0
for i in range(0, N):
    strings = list(input())
    strings.sort()
    key = "".join(strings)
    if not key in map:
        map[key] = 1
    else:
        count += map[key]
        map[key] += 1

print(count)

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

d = {}
ans = 0
for i in range(n):
    list_s = sorted(list(input()))

    s = ""
    for j in list_s:
        s = s + j

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

print(ans)

Solution (Python):
import collections

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += v * (v - 1) // 2

print(ret)

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

map = {}
count = 0
for i in range(0, N):
    strings = list(input())
    strings.sort()
    key = "".join(strings)
    if not key in map:
        map[key] = 1
    else:
        map[key] += 1

count = 0
for v in map.values():
    count += v * (v - 1) // 2
    
print(count)

Solution (Python):
import math

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    for i in range(1, v):
        ans += i
print(ans)

Solution (Python):


import math

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    for i in range(1, v):
        ans += i
print(ans)

Solution (Python):
import collections
n=int(input())
s=[0]*n
for i in range(n):
    s[i] = "".join(sorted(input()))
t=collections.Counter(s)
ans=0
for i in t.keys():
    ans+=t[i]*(t[i]-1)//2
print(ans)

Solution (Python):
import collections
n = int(input())
s = [input() for i in range(n)]
t = []
for i in range(n):
    t.append("".join(sorted(s[i])))
ans = 0

x = collections.Counter(t).values()
for i in x:
    ans += i*(i-1)/2
print(round(ans))

Solution (Python):

n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)

c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            if c>= 2:
                count += c*(c-1)//2
            c = 1
if c >=2:
    count += c*(c-1)//2
print(count)

Solution (Python):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)

c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            if c>= 2:
                count += cmb(c,2)
            c = 1
if c >=2:
    count += cmb(c,2)
print(count)

Solution (Python):
n = int(input())
dict = {}
ans = 0

for i in range(n):
    s = tuple(sorted(input()))
    if s in dict.keys():
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)

Solution (Python):
n = int(input())
dict = {}
ans = 0

for i in range(n):
    s = str(sorted(input()))
    if s in dict.keys():
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)

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

Solution (Python):
"""自分で考えたやつ

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

count = 0
for i in range(N):
    Si = S[i]
    for k in range(N):
        if i==k:
            None
        else:
            Sk = S[k]
            if Sk == Si:
                count += 1

print(count / 2)
"""

N = int(input())
dic = {}
ans = 0

for i in range(N):
    s = ''.join(sorted(input()))
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)