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())
strings = sorted(str(sorted(input())) for _ in range(N))

ans = 0
cnt = 1
for i in range(N - 1):
    if strings[i] == strings[i + 1]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
        cnt = 1
print(ans) if cnt <= 1 else print(ans + cnt * (cnt - 1) // 2)

Solution (Python):
import sys
from collections import defaultdict


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


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = str(sorted(input()))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Solution (Python):
from collections import defaultdict


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = str(sorted(input()))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Solution (Python):
from collections import defaultdict, Counter


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = [(k, v) for k, v in Counter(input()).items()]
    elem = tuple(sorted(elem))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Solution (Python):
from collections import defaultdict
import sys
input=sys.stdin.readline
N=int(input())

s_dic=defaultdict(int)
for i in range(N):
  s=list(input().rstrip())
  s.sort()
  s_str="".join(s)
  s_dic[s_str]+=1


answer=0
for val in s_dic.values():
  answer+=(val*(val-1))//2

print(answer)

Solution (Python):
import collections
n=int(input())
s=collections.Counter(["".join(sorted(input())) for _ in range(n)])
v=list(s.values())
res=0
for u in v:
	if u!=1:
		res += u*(u-1)//2
print(res)

Solution (Python):
P=[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]
n=int(input())
A=[1]*n

for i in range(n):
	s=input()
	for j in range(10):
		A[i] *= P[ord(s[j])-97]

res=0
A.sort()
cnt=0

for i in range(n-1):
		if A[i]==A[i+1]:
			cnt += 1
		else:
			res += cnt*(cnt+1)//2
			cnt=0
if cnt != 0:
	res += cnt*(cnt+1)//2
print(res)

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

N = int(input())
s = [sorted(input()) for _ in range(N)]
s.sort()
sum = 0
i = 1

for j in range(1,N):
  if s[j] == s[j-1]:
    i += 1
  else:
    if i > 1:
      sum += combinations_count(i, 2)
    i = 1
if i > 1:
      sum += combinations_count(i, 2)
    
  
print(sum)

Solution (Python):
N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
s.sort()
tmp = s[0]
t = 0
ans = 0
for x in s[1:]:
    if x == tmp:
        t += 1
    else:
        ans += t * (t + 1) // 2
        t = 0
        tmp = x
ans += t * (t + 1) // 2
print(ans)

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

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
c = Counter(["".join(sorted(input())) for _ in range(n)])
ans = 0
for w in c:
    ans += c[w] * (c[w] - 1)
print(ans // 2)

Solution (Python):
from collections import Counter
from scipy import misc
N = int(input())
c = []
for i in range(N):
    a = list(input())
    c.append(''.join(sorted(a)))
d = Counter(c)
print(sum([misc.comb(v,2,exact=True) for v in d.values() if v > 1]))

Solution (Python):
from collections import defaultdict

N = int(input())
S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  w = "".join(s)
  S[w] += 1

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

print(ans)

Solution (Python):
import math
from collections import Counter
n=int(input())
s = [str(sorted(list(input()))) for i in range(n)]
c = Counter(s)



ans=0
for i in c.values():
    if i>=2:
        x = (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
        ans+=x
print(ans)

Solution (Python):
import collections
n=int(input())
s=["".join(sorted(input())) for i in range(n)]
c=list(collections.Counter(s).values())
r=0
for x in c:
    if x!=1:r+=(x*(x-1)//2)
print(r)

Solution (Python):
import collections
n = int(input())
s = [0]*n
L = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	L[i] = ''.join(sorted(list(s[i])))
D = collections.Counter(L)
for i in D.values():
	ans += i*(i-1)//2
print(ans)

Solution (Python):
import collections
import math
n = int(input())
s = [0]*n
T = [0]*n
L = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	T[i] = sorted(list(s[i]))
	L[i] = ''.join(T[i])
D = collections.Counter(L)
for i in D.values():
	ans += i*(i-1)/2
print(int(ans))

Solution (Python):
n = int(input())
s = [str(input()) for _ in range(n)]
e = []
for i in range(n):
    e.append("".join(sorted(s[i])))
e.sort()
g = [1]
for i in range(n-1):
    if e[i] != e[i+1]:
        g.append(1)
    else:
        g[-1] += 1
ans = 0
for i in g:
    ans += (i*(i-1)//2)
print(ans)

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

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

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

print(res)

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

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

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

print(res)

Solution (Python):
n = int(input())
a = [sorted(input()) for i in range(n)]
from collections import Counter
b = []
for i in range(n):
    b.append(''.join(a[i]))
count = Counter(b)
ans = 0
for i in set(b):
    ans += count[i]*(count[i]-1)/2
print(int(ans))

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

standard = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    
    if s in standard:
        standard[s] += 1
    else:
        standard[s] = 1

ans = 0
for n in standard.values():
    ans += n * (n - 1) // 2

print(ans)

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


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

print(ans)

Solution (Python):
n = int(input())
x =[]
ch = 1
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    x.append(s)
x.sort()
x.append('X')
for i in range(n):
    if x[i]==x[i+1]:
        ch+=1
    else:
        ans += ch*(ch-1)//2
        ch = 1
print(ans)

Solution (Python):
N = int(input())
S = [list(input()) for i in range(N)]
for i in range(N):
    S[i].sort()
    S[i]=''.join(S[i])
S.sort()
word = S[0]
ans = 0
cnt = 1
for i in range(1,N):
    if(word == S[i]):
        cnt += 1
    else:
       	ans += cnt*(cnt-1)//2
       	cnt = 1
    word = S[i]
    if(i == N-1):
        ans += cnt*(cnt-1)//2
print(ans)

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

d = dict()
for i in range(n):
  s = "".join(sorted(list(input())))
  d[s] = d.get(s, 0) + 1
  
ans = 0
for key in d:
  ans += d[key] * (d[key]-1) // 2
  
print(ans)

Solution (Python):
def f(n):
  return (n**2-n)//2
N=int(input())
A=[]
for i in range(N):
  S=sorted(input())
  A.append("".join(S))
A=sorted(A)
A.append("")
ans=0
n=1
for i in range(N):
  if A[i]==A[i+1]:
    n+=1
  else:
    ans+=f(n)
    n=1
print(ans)

Solution (Python):
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

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

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 

n = int(input())
s = []
for _ in range(n):
    s.append(''.join(sorted(input())))
s.sort()
ans = 0
cnt = 0
for i in range(1, n):
    if s[i - 1] == s[i]:
        cnt += 1
    else:
        ans += (cnt * (cnt + 1) // 2)
        cnt = 0
else:
    ans += (cnt * (cnt + 1) // 2)
print(ans)

Solution (Python):


from collections import defaultdict

d = defaultdict(int)
n = int(input())

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

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

print(ans)

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

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

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

print(ans)

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

Solution (Python):
def main():
	n = int(input())
	arr = []
	dictionary = {}
	cnt = 0
	for _ in range(n):
		arr.append(str(input()))
	for i in range(n):
		l = list(arr[i])
		l.sort()
		arr[i] = ''.join(str(l))
	for i in range(n):
		if arr[i] in dictionary:
			dictionary[arr[i]]+=1
			cnt+=dictionary[arr[i]]
		else:
			dictionary[arr[i]]=0
	print(cnt)
	



main()

Solution (Python):





import collections

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

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


c = collections.Counter(s)
pairs = c.most_common()

for i in range(len(pairs)):
    pair_i = pairs[i][1]
    if pair_i > 1:
        cnt += pair_i * (pair_i-1) // 2

print(cnt)

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

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):
n = int(input())
s = ["".join(sorted(str(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):
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 collections import Counter
n = int(input())
s = [[0]*10 for _ in range(n)]
ans = 0
for i in range(n):
    str_s = input()
    for j in range(10):
        s[i][j] = str_s[j]

dict_s = {}
for i in range(n):
    s[i].sort()
    si = "".join(s[i])
    dict_s.setdefault(si, 0)
    dict_s[si] += 1

for x in dict_s.values():
    ans += x*(x-1)//2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
s = [[0]*10 for _ in range(n)]
ans = 0
for i in range(n):
    str_s = input()
    for j in range(10):
        s[i][j] = str_s[j]

dict_s = {}
for i in range(n):
    s[i].sort()
    si = "".join(s[i])
    dict_s.setdefault(si, 0)
    dict_s[si] += 1

for x in dict_s.values():
    ans += x*(x-1)//2
print(ans)

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

l.sort()
cnt=0
tmp=0

for i in range(1,len(l)):
    if l[i]==l[i-1]:
        tmp += 1
    else:
        cnt += (tmp+1)*tmp//2
        tmp=0
cnt += (tmp+1)*tmp//2
print(cnt)

Solution (Python):
from collections import Counter

n = int(input())
l = list("")
for i in range(n):
    s = ''.join(sorted(input()))
    l.append(s)
c = Counter(l)
c = c.most_common()
ans = 0
for i in range(len(c)):
    x = c[i][1] - 1
    while x > 0:
        ans += x
        x -= 1
print(ans)

Solution (Python):
n = int(input())
a = {}
for i in range(n):
  tmp = "".join(sorted(input()))
  if tmp in a:
    a[tmp] += 1
  else:
    a[tmp] = 1
res = [i*(i-1)//2 for i in a.values()]
print(sum(res))

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


dic = {}

for i in range(n):
    sen = '・'.join(sorted(s[i]))
    
    if sen not in dic:
        dic[sen]=1
    else:
        dic[sen]+=1    

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

Solution (Python):

n = int(input())
dic = {}
for i in range(n):
    s = "".join(sorted(input()))
    dic.setdefault(s, 0)
    dic[s] += 1
ans = 0
for x in dic.values():
    ans += int(x * (x - 1) / 2)
print(ans)

Solution (Python):

n = int(input())
dic = {}
for i in range(n):
    t = ''.join(sorted(input()))
    dic.setdefault(t, 0)
    dic[t] += 1
ans = 0
for x in dic.values():
    ans += x * (x - 1) // 2
print(ans)

Solution (Python):

n = int(input())
dic = {}
for i in range(n):
    t = ''.join(sorted(input()))
    dic.setdefault(t, 0)
    dic[t] += 1
ans = 0
for x in dic.values():
    ans += x * (x - 1) // 2
print(ans)

Solution (Python):
from collections import Counter
import math
n=int(input())
s=list(input() for _ in range(n))
S=[]
ans=0
for i in range(n):
    s1=sorted(s[i])
    S.append(''.join(s1))
S1=Counter(S)
for i in S1:
   if S1[i]>1:
        ans+=math.factorial(S1[i])//(math.factorial(S1[i]-2)*2)
print(ans)

Solution (Python):
from collections import Counter

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

def main():
    t = ["".join(sorted(t)) for t in s]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)
main()

Solution (Python):
from collections import Counter
from math import factorial
N = int(input())
S = []
for i in range(N):
    tmp = input()
    tmp = sorted(list(tmp))
    S.append("".join(tmp))

cnt = Counter(S)
ans = 0
for i in cnt:
    if cnt[i] > 1:
        ans += factorial(cnt[i]) // (factorial(cnt[i] - 2) * factorial(2))

print(ans)

Solution (Python):
from math import factorial, ceil
n = int(input())
d = {}
for i in range(n):
    s = input()
    ns = ''.join(sorted(s))
    if ns not in d.keys():
        d[ns] = 1
    else:
        d[ns] += 1
ans = 0
for i, v in d.items():
    if v != 1:
        ans += factorial(v) /(factorial(v-2)*2)
print(int(ans))

Solution (Python):
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
import collections
A = []
for a in S:
    A.append("".join(a))
count = 0
c = collections.Counter(A)
for a in c.values():
    count += a*(a-1)//2

print(count)

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

dic = {}
for w in s:
    if w in dic:
        dic[w] += 1
    else:
        dic[w] = 1

ans = 0
for w in dic:
    ans += dic[w] * (dic[w] - 1) // 2

print(ans)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    s=input()
    k=[]
    for i in range(10):
        k.append(s[i])
    k.sort()
    p="".join(k)
    a.append(p)
a.sort()
bef=a[0]
cnt=0
sum=0
for i in range(n):
    if bef==a[i]:
        cnt+=1
    else:
        sum+=(cnt*(cnt-1)//2)
        cnt=1
        bef=a[i]
    if i==n-1:
        sum+=(cnt*(cnt-1)//2)
print(sum)

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

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

for i in range(N):
    s=input()
    t=sorted(s)
    word="".join(t)

    if word in dic:
        dic[word]+=1
    else:
        dic[word]=1

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

print(ans)

Solution (Python):
import math
N = int(input())
L = []
for i in range(N):
    s = input()
    L.append(sorted(s))
L = sorted(L)
ans = 0
comb = 0
a = 0
b = 1
while b <= N-1:
    if L[a] == L[b] and b-a == 1:
        comb += 2
        b += 1
    elif L[a] == L[b]:
        comb += 1
        b += 1
    elif comb != 0:
        ans += (math.factorial(comb))//((math.factorial(comb-2))*2)
        a = b
        b = a+1
        comb = 0
    else:
        a = b
        b = a + 1
if comb != 0:
    ans += (math.factorial(comb)) // ((math.factorial(comb - 2)) * 2)
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())

temp_dict = defaultdict(int)
for _ in range(n):
    s_list = list(input())
    s_list.sort()
    s = "".join(s_list)
    temp_dict[s] += 1

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

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

temp_dict = {}
for _ in range(n):
    s_list = list(input())
    s_list.sort()
    s = "".join(s_list)

    if s not in temp_dict:
        temp_dict[s] = 0
    temp_dict[s] += 1

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

Solution (Python):
from collections import Counter
from scipy.misc import comb
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
ans = 0
for count in Counter(s).values():
    ans += comb(count, 2, exact=True)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    lis=[]
    ans=0
    for i in range(n):
        s=input()
        s_c=Counter(s)
        s_ct=tuple(sorted(s_c.items()))
        lis.append(s_ct)
    lis_c=Counter(lis)
    for li in lis_c.items():
        x=li[1]
        if x>=2:
            ans+=x*(x-1)//2
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    lis=[]
    ans=0
    for i in range(n):
        s=input()
        s_c=Counter(s)
        s_ct=tuple(sorted(s_c.items()))
        lis.append(s_ct)
    lis_c=Counter(lis)
    for li in lis_c.items():
        x=li[1]
        if x>=2:
            ans+=x*(x-1)//2
    print(ans)

if __name__=='__main__':
    main()

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

Solution (Python):
import itertools
from collections import Counter
import math

N = int(input())

def generate_prime_numbers():
    search_range = 150
    search_list = [True for i in range(0, search_range+1)]
    search_list[0] = False
    search_list[1] = False
    search_list[2] = True
    for i in range(2, search_range+1):
        for j in range(i*2, search_range+1, i):
            search_list[j] = False
    prime_numbers = [i for i in range(search_range+1) if search_list[i] == True]
    return prime_numbers[:27]

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

prime_numbers = generate_prime_numbers()
encoded_strings = []
for i in range(N):
    S = input()
    encoded_string = 1
    for c in S:
        char_to_int = ord(c) - ord('a')
        encoded_string *= prime_numbers[char_to_int]
    encoded_strings.append(encoded_string)


ans = 0



counter = Counter(encoded_strings)
for i in counter.values():
    if i > 1:
        ans += combination(i, 2)

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = [list((map(str,input().split()))) for _ in range(N)]

A = []
for i in S:
    ew_str = ''.join(sorted(i[-1]))
    A.append(ew_str)

cnt = Counter(A)
cnt = list(cnt.values())


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

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

def ncr(n, r):
	if n < r:
		return 0
	else :
		return (math.factorial(n)) / (math.factorial(n-r)*math.factorial(r))

def countPairs(str_arr, N):
	str_cnt = [0]
	str = str_arr[0]
	j = 0
	for i in range(N):
		if(str_arr[i]==str):
			str_cnt[j] += 1
		else:
			str = str_arr[i]
			j += 1
			str_cnt.append(0)
			str_cnt[j] += 1
	count = 0
	for i in range(len(str_cnt)):
		count += ncr(str_cnt[i],2)
	print(int(count))

def main():
	N = int(input())
	str_arr = []
	for i in range(N):
		str = input()
		str_arr.append(sorted(str))
	str_arr = sorted(str_arr)
	countPairs(str_arr, N)


main()

Solution (Python):
from collections import Counter
n = int(input())
ans = []
cnt = 0
for i in range(n):
    s = input()
    l = list(s)
    l.sort()
    ans.append("".join(l))
c = Counter(ans)


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

print(cnt)

Solution (Python):
import sys
from collections import Counter

n,*S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)
main()

Solution (Python):
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

from collections import Counter
counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Solution (Python):
from collections import Counter
n = int(input())
S = Counter()
ans = 0
for _ in range(n):
    s = "".join(sorted(input()))
    if S[s] > 0:
        ans += S[s]
    S[s] += 1

print(ans)

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

Solution (Python):



import sys
import numpy as np

n=int(sys.stdin.readline())
s=list([sorted(list(sys.stdin.readline().strip())) for _ in range(n)])
s.sort()

pre=''
cnt=0
ans=0
for i in range(n):
    now=s[i]
    if pre==now:
        cnt+=1
    else:
        pre=now
        ans+=(cnt+1)*cnt//2
        cnt=0
ans+=(cnt+1)*cnt//2
print(ans)

Solution (Python):
from collections import Counter
from scipy.misc import comb
print(sum(comb(n, 2, exact=True) for n in Counter("".join(sorted(input())) for _ in range(int(input()))).values()))

Solution (Python):
from collections import Counter
from scipy.misc import comb
N = int(input())
print(sum(comb(n, 2, exact=True) for n in Counter("".join(sorted(input())) for _ in range(N)).values()))

Solution (Python):
from collections import defaultdict

a = int(input())


d=defaultdict(int)


for _ in range(a):
     b = input()
     c = "".join(sorted(b))
     d[c] +=1
    
    

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


print(sum)

Solution (Python):
def main():
    n = int(input())
    anag = {}
    for i in range(n):
        s = sorted(input())
        if not str(s) in anag.keys():
            anag[str(s)] = 1
        else:
            anag[str(s)] += 1
    s = 0
    for k in anag.keys():
        s += anag[k]*(anag[k]-1)//2
    print(s)


if __name__ == "__main__":
    main()

Solution (Python):

















mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    dic = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1

    def comb(n,r,p = mod):
        r = min(r,n-r) 
        res = 1
        div = 1 
        for i in range(n-r+1,n+1):
            res *= i
            res %= p
        for i in range(1,r+1):
            div *= i
            div %= p
        res *= pow(div,p-2,p) 
        res %= p
        return res
    ans = 0
    for k,v in dic.items():
        ans += v * (v-1) // 2
    print(ans)

if __name__ == '__main__':
  main()

Solution (Python):


import sys








from itertools import groupby                










def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    L = [''.join(sorted(list(input()))) for _ in range(n)]
    L.sort()
    ans = 0
    for k, g in groupby(L):
        size = len(list(g))
        ans += size * (size-1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    N = int(input())

    d = defaultdict(int)

    def string_sort(s):
        return str(sorted(s))
        
        

        

    ans = 0
    for _ in range(N):
        s = string_sort(input().rstrip())
        ans += d[s]
        d[s] += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    N = int(input())

    d = defaultdict(int)

    def string_sort(s):
        return ''.join(sorted(s))

    ans = 0
    for _ in range(N):
        s = string_sort(input().rstrip())
        ans += d[s]
        d[s] += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip()) for _ in range(n)]

set_list = {}

for i in li:
    i.sort()
    s = "".join(i)
    if s in set_list:
        set_list[s] += 1
    else:
        set_list[s] = 1

point = 0

for i in set_list.values():
    point += i*(i-1)//2

print(point)

Solution (Python):
from sys import stdin
from math import factorial

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

n = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip()) for _ in range(n)]

set_list = {}

for i in li:
    i.sort()
    s = "".join(i)
    if s in set_list:
        set_list[s] += 1
    else:
        set_list[s] = 1

point = 0

for i in set_list.values():
    if i >= 2:
        point += combinations_count(i,2)

print(point)

Solution (Python):
N = int(input())
S = {}
for _ in range(N):
  s = "".join(sorted(input()))
  if not s in S: S[s] = 0
  else: S[s] += 1

ans = 0
for v in S.values():
  if v < 2: ans += v
  else: ans += v * (v+1) // 2
print(ans)

Solution (Python):


from collections import Counter


N = int(input())
s_list = []
for i in range(N):
    s = sorted(input())
    s = "".join(s)
    s_list.append(s)


ct = Counter(s_list)
ans = 0


for c in ct.most_common():
    tmp_ct = c[1]
    if tmp_ct==1:
        continue
    ans += tmp_ct * (tmp_ct-1) // 2


print(ans)

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, 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 heapq import heapify, heappop, heappush

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 = [input() for i in range(N)]

memo = defaultdict(int)
L = []
for i in range(N):
    l = list(S[i])
    l.sort()
    l = "".join(l)
    memo[str(l)] += 1

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

Solution (Python):
N = int(input())
A = []
D = {}
cnt = 0

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

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

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: 0)
for _ in range(n):
    s = list(input())
    s.sort()
    d[''.join(s)] += 1
ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Solution (Python):
def resolve():
    n = int(input())
    dict = {}
    s = [",".join(sorted(input())) for _ in range(n)]
    count = 0
    for i in range(n):
        if s[i] in dict:
            count += dict[s[i]]
            dict[s[i]] += 1
        else:
            dict[s[i]] =1

    print(count)
resolve()

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

from collections import defaultdict
dic = defaultdict(int)

for _ in range(n):
    s = list(input())
    s = tuple(sorted(s))
    dic[s] += 1

ans = 0
for s in dic:
    ans += dic[s] * (dic[s] - 1) // 2

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 collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    D = defaultdict(lambda : 0)
    ans = 0
    for i in range(n):
        d = [0]*26
        s = input()
        for j in s:
            d[ord(j)-ord("a")] += 1
        td = tuple(d)
        ans += D[td]
        D[td] += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()