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):


from collections import Counter
N = int(input())

s_list = []
for i in range(N):
    input_string = list(input())
    input_string.sort()
    input_string = "".join(input_string)
    s_list.append(input_string)

s_list.sort()

list_counter = Counter(s_list)

count = 0
for key in list_counter.keys():
    tmp_count = list_counter[key]
    if tmp_count < 2:
        pass
    elif tmp_count == 2:
        count += 1
    else:
        permutations = tmp_count * (tmp_count - 1)
        combination = permutations/2
        count += int(combination)

print(int(count))

Solution (Python):
N = int(input()) 
s = [input() for i in range(N)]
LIS=[]
for i in range(N):
  LIS.append(''.join(sorted(s[i])))
LIS.sort()
n=0
prestr=LIS[0]
count=1
for st in LIS[1:]:
  if st==prestr:
    n+=count
    count+=1
  else:
    count=1
    prestr=st
print(int(n))

Solution (Python):
import math
import collections

n=int(input())
a=[list(input()) for i in range(n)]
b=[str(sorted(list(i))) for i in a]
count=list(collections.Counter(b).values())
count=[i for i in count if i>1]
print(int(sum([math.factorial(x)/(math.factorial(x-2)*2) for x in count])))

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):
n = int(input())
s = [input() for i in range(n)]
t = {}
cnt = 0
for i in s:
    tmp = "".join(sorted(list(i)))
    if tmp in t:
        t[tmp] += 1
        cnt += t[tmp]
    else:
        t[tmp] = 0
    
print(cnt)

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

Solution (Python):
def main():
    N = int(input())
    cnt = {}
    ans = 0
    for _ in range(N):
        s = input()
        ss = "".join(sorted(list(s)))
        if ss not in cnt:
            cnt[ss] = 0
        ans += cnt[ss]
        cnt[ss] += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

n=int(input())
s=["".join(sorted(list(input()))) for _ in range(n)]
from collections import Counter
c=Counter(s)
x=list(c.values())
res=0
for t in x:
	res+=t*(t-1)//2
print(res)

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

d = {}
ans = 0
for s in S:
    s = "".join(sorted(s))
    if s in d:
        ans += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(ans)

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

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

print(ans)

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

d = {}
for s in S:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for v in d.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

Solution (Python):
N = int(input())
A=[]
count=1
ss=0
for i in range(0,N):
    A.append(list(input()))
    A[i].sort()
A.sort()
A.append('0')
for j in range(1,N+1):
    if A[j-1]==A[j]:
        count+=1
        j+=1
    else:
        ss+=count*(count-1)/2
        count = 1
        j+=1

print(int(ss))

Solution (Python):
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

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

Solution (Python):
import collections
N = int(input())
s = []
for i in range(N):
  word = input()
  chars = []
  sortedWord = ''

  for j in range(10):
    chars.append(word[j])
    chars.sort()

  
  
  for j in range(10):
    sortedWord += chars[j]

  

  s.append(sortedWord)

c = collections.Counter(s)

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

print(int(sum))

Solution (Python):
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 = [input() for _ in range(N)]

d = {}
for s in S:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for v in d.values():
    if v > 1:
        ans += cmb(v, 2)
print(ans)

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

D = {}
cnt = 0
for str in S:
    if str in D:
        cnt += D[str]
        D[str] += 1
    else:
        D[str] = 1

print(cnt)

Solution (Python):
N = int(input())
ss = []
for _ in range(N):
    ss.append(''.join(sorted(input())))
d = {}
for s in ss:
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
print(sum(int((v * (v - 1)) / 2) for v in d.values() if v > 1))

Solution (Python):
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

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

Solution (Python):


N=int(input())
s=[list(input()) for i in range(N)]
total=0
dic={}
for l in range(N):
    s[l].sort()
    if dic.get(str(s[l]))==None:
        dic[str(s[l])]=0
    else:
        dic[str(s[l])]+=1
        total+=int(dic[str(s[l])])
print(total)

Solution (Python):


N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
dic={}
for l in range(N):
    s[l].sort()
    if dic.get(str(s[l]))==None:
        dic[str(s[l])]=0
    else:
        dic[str(s[l])]+=1
        total+=int(dic[str(s[l])])
print(total)

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

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

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

print(ans)

Solution (Python):
n = int(input())
mojiretues = []
for _ in range(n):
	s = list(input())
	s.sort()
	mojiretues.append("".join(s))
mojiretues.sort()

prestr = mojiretues[0]
cnt = 1
ans = 0
for s in mojiretues[1:]:
	if prestr == s:
		ans += cnt
		cnt += 1
	else:
		prestr = s
		cnt = 1

print(ans)

Solution (Python):
n = int(input())
mojiretues = []
for _ in range(n):
	s = list(input())
	s.sort()
	mojiretues.append("".join(s))
mojiretues.sort()

prestr = mojiretues[0]
cnt = 1
ans = 0
for s in mojiretues[1:]:
	if prestr == s:
		ans += cnt
		cnt += 1
	else:
		prestr = s
		cnt = 1

print(ans)

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

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

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    if w2 in wordl:
        ans += wordl[w2]
        wordl[w2] += 1
    else:
        wordl[w2] = 1

print(ans)

'''

N = int(input())
wordl = []

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    wordl.append(w2)
wordl.sort()


ans = 0
for k in range(N):
    for q in range(k+1,N):
        if wordl[k] == wordl[q]:
            ans += 1
        else:
            break

print(ans)
'''

Solution (Python):
N = int(input())
S = [''.join(sorted(input())) for _ in range(0, N)]
d = {}
result = 0
for s in S:
    if s in d.keys():
        result += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(result)

Solution (Python):
from collections import defaultdict
N = int(input())
dct = defaultdict(int)

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

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

print(ans)

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

Solution (Python):
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

lis=[]
for i in range(n):
    lis.append(ans[i][0])
    for j in range(9):
        lis[i]+=ans[i][j+1]

a=0


dic={lis[0]:1}
for i in range(n-1):
    if lis[i+1] in dic.keys():
        a+=dic[lis[i+1]]
        dic[lis[i+1]]+=1
    else:
        dic[lis[i+1]]=1

print(int(a))

Solution (Python):
from collections import defaultdict
n = int(input())
ans = 0
spc = defaultdict(int)

for _ in range(n):
    s = "".join(sorted(list(str(input()))))
    if s in spc:
        ans += spc[s]
        spc[s] += 1
    else:
        spc[s] = 1

print(ans)

Solution (Python):


import sys
import collections
from operator import mul
from functools import reduce

def input():
    return sys.stdin.readline().rstrip()
    
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())
a = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(a)
c_array = list(filter(lambda x: x >= 2, c.values()))
ctr = 0

for i in c_array:
    ctr += cmb(i, 2)
print(ctr)

Solution (Python):
import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":59, "r":61, "s":67, "t":71, "u":73, "v":79, "w":83, "x":89, "y":97, "z":1}

S = [input() for _ in range(N)]

for s in S:
    s1 = [D[x] for x in s]
    s2 = np.prod(s1)

    if s2 in Sdict:
        n_anagram = n_anagram + Sdict[s2]
        Sdict[s2] += 1
    else:
        Sdict[s2] = 1
   
print(n_anagram)

Solution (Python):


import sys
import collections
from operator import mul
from functools import reduce

def input():
    return sys.stdin.readline().rstrip()
    
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())
a = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(a)
c_array = list(filter(lambda x: x >= 2, c.values()))
ctr = 0

for i in c_array:
    ctr += cmb(i, 2)
print(ctr)

Solution (Python):
N=int(input())
a=[]
for i in range(N):
    s=list(str(input()))
    a.append(tuple(sorted(s)))

a=sorted(a)

ans=[]
count=0
for i in range(1,N):
    if a[i]==a[i-1]:
        count +=1
    elif a[i]!=a[i-1] and count >=1:
        ans.append(count)
        count=0

if count>=1:
    ans.append(count)


ans2=0
for i in ans:
    ans2 += (i+1)*i//2

print(ans2)

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

Solution (Python):


from collections import defaultdict


dct = defaultdict(lambda:0)

N = int(input())
for _ in range(N):
  s = "".join(sorted(str(input())))
  dct[s] += 1

ans = 0
for k in dct:
  if dct[k] > 1:
    ans += dct[k]*(dct[k]-1)//2
print(ans)

Solution (Python):
import math
num = int(input())
words = {}

for i in range(num):
  a = str(sorted(list(input())))
  
  if a in words:
    words[a] += 1
  else:
  	words[a] = 1

points = list(words.values())
sum = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(len(points)):
  if points[i] > 1:
  	sum += combinations_count(points[i], 2)
print(sum)

Solution (Python):
N = int(input())
ans = 0
dict_word = {}
for i in range(N):
  sorted_word = str(''.join(sorted(list(input()))))
  try:
    ans += dict_word[sorted_word]
    dict_word[sorted_word] += 1
  except:
    dict_word[sorted_word] = 1
print(ans)

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

b =[""]*N
 
cn =ord("a")
 
for i in range(N):
    s = list(input())
    s.sort()
    b[i] ="".join(s)
 
b.sort()
c = 0
ans =0
 
for i in range(N-1):
    if b[i]==b[i+1]:
        c +=1
    else:
        if c !=0:
            ans=ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
            c = 0
 
 
if c !=0:
    ans = ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
    
 
print(int(ans))

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
S = [stdin.readline().rstrip() for _ in range(N)]
count = {}

for s in S:
    s = ''.join(sorted(s))
    if s not in count:
        count[s] = 1
    else:
        count[s] += 1

ans = 0
for c in count:
    if count[c] > 1:
        ans += count[c] * (count[c] - 1) // 2

print(ans)

Solution (Python):
def sum_list(i):
    return int((i*(i+1))/2)

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

ls.sort()
ans = 0
count = 0

for i in range(len(ls)):
    if (ls[i] == ls[i+1]):
        count += 1
    else:
        ans += sum_list(count)
        count = 0
    if (i == n-2):
      ans += sum_list(count)
      break

print(ans)

Solution (Python):
n = int(input())
ans = 0
dict = {}
for _ in range(n):
  	
    s = str(''.join(sorted(list(input()))))
    try:
        ans += dict[s]
        dict[s] += 1
    except:
        dict[s] = 1
print(ans)

Solution (Python):
n=int(input())
s=sorted([sorted(map(str,input())) for _ in [0]*n])+[[]]
c=0
i=0
while i<n:
    j=0
    while s[i+j+1]==s[i]:j+=1
    c+=j*(j+1)//2
    i+=j+1
print(c)

Solution (Python):
n=int(input())
d={}
ans=0
for i in range(n):
    s=sorted(list(input()))
    e=""
    for v in range(10):
        e+=s[v]
    if e in d:
        d[e]+=1
    else:
        d[e]=1
for _ in d:
    if d[_]==1:
        pass
    else:
        ans+=d[_]*(d[_]-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 i in d.values(): ans += i*(i-1)//2
print(ans)

Solution (Python):
n = int(input())
ans = 0
dict = {}
for _ in range(n):
    s = str(''.join(sorted(list(input()))))
    try:
        ans += dict[s]
        dict[s] += 1
    except:
        dict[s] = 1
print(ans)

Solution (Python):
from collections import defaultdict

strings = defaultdict(int)
n = int(input())

res = 0

for _ in  range(n):
    temp = ''.join(sorted(list(input())))
    strings[temp] += 1
    res += strings[temp] - 1

print(res)

Solution (Python):
def nck(n):
    ret = 1
    for i in range(2):
        ret *= (n - i)
    return ret//2

N = int(input())
S = {}
for i in range(N):
    s = str(sorted(input()))
    if s not in S.keys():
        S[s] = 0
    S[s] += 1
ans = 0
for key in S.keys():
    if S[key] > 1:
        ans += nck(S[key])
print(ans)

Solution (Python):
import collections
n = int(input())
strs = ["".join(sorted(input())) for _ in range(n)]
d = collections.Counter(strs)
ans=0
for x in d.values():
  ans += x*(x-1)/2

print(int(ans))

Solution (Python):
def resolve():
    N = int(input())
    S = sorted(list(sorted(input()) for _ in range(N)))
    count = 0
    S_dict = {}
    for i in range(N):
        s = str(S[i])
        if s in S_dict:
            tmp =  S_dict[s]
            S_dict[s] = tmp + 1
            count = count + tmp
        else:
            S_dict.setdefault(s,1)
    print(count)

    
resolve()

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

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

from collections import Counter
counter = Counter(s)

print(sum([x*(x-1)//2 for x in counter.values()]))

Solution (Python):
from math import factorial
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
count = 0

for d in dic.values():
    
    if d > 2:
        count += factorial(d) // 2 // factorial(d - 2)
    elif d == 2:
        count += 1
print(count)

Solution (Python):
n = int(input())
strings = []
for i in range(n):
    s = input()
    s10 = []
    for j in range(10):
        s10.append(s[j])
        s10.sort()
    s = ''
    for j in range(10):
        s += s10[j]
    strings.append(s)

set_strings = dict()

for i in range(n):
    if not strings[i] in set_strings.keys():
        set_strings[strings[i]] = 1
    else:
        set_strings[strings[i]] += 1

count = 0
for num in set_strings.values():
    count += num * (num - 1) / 2
print(int(count))

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

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

dic = {}
cnt = 0
for i in range(N):
    if s[i] in dic:
        cnt += dic[s[i]]
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1
print(cnt)

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

count = 0
dic1 = {}

for i in range(n):
    
    so = ''.join(s[i])
    
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    
print(count)

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

ans = 0
d = {}
for i in s:
    a = [c for c in i]
    a.sort()
    a = "".join(a)
    if a in d:
        ans+= d[a]
        d[a] +=1
    else:
        d[a] = 1
print(ans)

Solution (Python):
def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    res = [0] * len(temp)
    cnt = 0
    for x in array:
        res[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ''.join([str(i) for i in res])

N = int(input())
s = [''.join(f(input())) for i in range(N)]

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

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

print(cnt)

Solution (Python):
def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    ret = [0] * len(temp)
    cnt = 0
    for x in array:
        ret[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ret

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

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

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

print(cnt)

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

count = 0
dic1 = {}

for i in range(n):
    
    so = ''.join(s[i])
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    
print(count)

Solution (Python):
n = int(input())
dic = {}
pair = 0

for i in range(n):
  line = "".join(sorted(input()))
  if line in dic:
    dic[line] += 1
  else:
    dic[line] = 1
  
for value in dic.values():
  pair += (value * (value-1)) / 2
  
print(int(pair))

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
st = dict()
for o in s:
    if "".join(sorted(o)) in st:
        st["".join(sorted(o))] += 1
    else:
        st["".join(sorted(o))] =  1
ans = 0
for i in st.values():
    ans += i*(i-1)//2
print(ans)

Solution (Python):
import math
from collections import defaultdict

n = int(input())

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






cnt = 0

d = defaultdict(lambda: 0)
for s in s_l:
        d[s] += 1

for v in d.values():
        cnt += int(v*(v-1)/2)
print(cnt)

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

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
Ss = {}
for i in range(N):
    s = ''.join(sorted(list(input().rstrip("\n"))))
    if s in Ss:
        Ss[s] += 1
    else:
        Ss[s] = 1

c = 0
for s in Ss.values():
    c += (s - 1) * s >> 1

print(c)

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

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip("\n"))) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c // 2

print(Su)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c // 2

print(Su)

Solution (Python):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
gi = lambda : list(map(int,input().split()))
n, = gi()
ans = 0
mp = {}
while n:
	s = "".join(sorted(list(input())))
	if s in mp:
		ans += mp[s]
		mp[s] += 1
	else:
		mp[s] = 1
	n -= 1
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c

print(Su // 2)

Solution (Python):
def resolve():
    import sys
    input = sys.stdin.readline
    N = int(input())
    Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

    import collections
    Co = collections.Counter(Ss)
    Su = 0
    for _, c in Co.most_common():
        if c < 2:
            break
        Su += (c - 1) * c

    print(Su // 2)

if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter
N = int(input())
S = set()
cnt = 0

def createStr(intput_str):
    ret = ""
    intput_str = sorted(intput_str)
    for s in intput_str:
        ret += s
    return ret

ret = {}
for i in range(N):
    s = createStr(input())
    if s in ret.keys():
        ret[s] += 1
    else:
        ret[s] = 1

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

print(cnt)

Solution (Python):
from collections import Counter
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
d=Counter(c)
an=0

for i in d.values():
    for j in range(i):
        an+=j

print(an)

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

d = dict.fromkeys(strs, 0)
for s in strs:
    if s in d.keys():
        d[s] += 1
    else:
        d.setdefault(s, 1)

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

print(int(ans))

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

Solution (Python):
from collections import defaultdict
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
d = defaultdict(lambda: 0)

for _s in s:
    d[_s] += 1

print(sum(map(lambda x: x * (x-1) // 2, d.values())))

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

Solution (Python):
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)

Solution (Python):
n = int(input())
s = sorted([sorted(input()) for i in range(n)])
a = []
last = s[0]
count = 1
for i in range(1, n):
    if s[i] == last:
        count += 1
    else:
        a.append(count)
        count = 1
    last = s[i]
a.append(count)
ans = 0
for i in a:
    if i > 1:
        ans += i * (i - 1) // 2
print(ans)

Solution (Python):
from collections import Counter

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

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

print(cnt)

Solution (Python):
def main():
  n = int(input())
  sdic = {}
  for _ in range(n):
    s = [_s for _s in sorted(input().strip())]
    s = ''.join(s)
    if s in sdic:
      sdic[s] += 1
    else:
      sdic[s] = 1
  ans = 0
  for k, v in sdic.items():
    ans += v*(v-1)//2
  print(ans)


if __name__ == '__main__':
  main()

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

strs.sort()


cnts = []
pre = strs[0]
cnt = 1
for str in strs[1:]:
  if str == pre:
    cnt += 1
  else:
    cnts += [cnt]
    pre = str
    cnt = 1
cnts += [cnt]



ans = 0
for cnt in cnts:
  if cnt == 1:
    continue
  ans += cnt * (cnt - 1) / 2
  
print(int(ans))

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

mP = dict()
for i in range(N):
    s = "".join(sorted(list(vS[i])))
    if s in mP.keys():
        mP[s] += 1
    else:
        mP[s] = 1

count = 0
vC = []
for key in mP:
    if (mP[key] < 2):
        continue
    vC.append(mP[key])
    count += 1

res = 0
for x in vC:
    res += x * (x-1) // 2

print(res)

Solution (Python):
N = int(input())
d = {}
for i in range(N):
  s = "".join(sorted(input()))
  if s in d.keys():
    d[s] += 1
  else:
    d.setdefault(s, 1)
count = 0
for v in d.values():
  count += (v-1)*v//2
print(count)

Solution (Python):
import collections

N = int(input())
s = [0] * N
for i in range(N):
    s[i] = list(input())
    s[i].sort()
    s[i] = ''.join(s[i])

c = collections.Counter(s)
l = list(c.values())


ans = 0
for i in range(len(l)):
    tmp = (l[i] * (l[i] - 1)) // 2
    ans += tmp

print(ans)

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

count = 0
dic1 = {}

for i in range(n):
    
    so = sorted(s[i])
    so = ''.join(so)
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    
print(count)

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

ans = 0

w = None
cnt = 0
path = 0
for x in s:
    if x != w:
        ans += path
        if x is None:
            break
        path = 0
        cnt = 1        
        w = x
    else:
        path += cnt
        cnt += 1

print(ans)

Solution (Python):
n = int(input())
m = {}
for i in range(n):
	s = input()
	l = list(map(str, s))
	s = "".join(sorted(l))
	if s in m:
		m[s] += 1
	else:
		m[s] = 1
res = 0
for i in m.keys():
	if m[i] > 1:
		res += m[i] * (m[i] - 1) // 2
print(res)

Solution (Python):
from collections import defaultdict

n = int(input())
ana_dict = defaultdict(int)
n_pair = 0
for _ in range(n):
    s = input()
    t = [0,] * 26
    for c in s:
        t[ord(c) - ord('a')] += 1
    t = tuple(t)
    if t in ana_dict:
        n_pair += ana_dict[t]
    ana_dict[t] += 1
print(n_pair)

Solution (Python):
from sys import stdin

readline = stdin.readline
def main():
    _, *keys = map(lambda s: ''.join(sorted(s.rstrip())), open(0))
    
    primes = {}
    res = 0
    for key in keys:
        if key in primes:
            res += primes[key]
            primes[key] += 1
        else:
            primes[key] = 1
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

readline = stdin.readline
def main():
    
    _, *keys = map(lambda s: tuple(sorted(s)), open(0))
    primes = {}
    res = 0
    for key in keys:
        if key in primes:
            res += primes[key]
            primes[key] += 1
        else:
            primes[key] = 1
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ss = [sorted(input()) for i in range(n)]
ss.sort()

tmp = ss[0]
cnt = 0
ans = 0
for i in range(n):
    if tmp == ss[i]: cnt+=1
    else:
        tmp = ss[i]
        ans += cnt*(cnt-1)//2
        cnt=1
print(ans+cnt*(cnt-1)//2)

Solution (Python):
from collections import defaultdict
n = int(input())
arr = []
d = defaultdict(int)
count = 0

for i in range(n):
  arr.append(input())
  arr[i] = "".join(sorted(arr[i]))
  count += d[arr[i]]
  d[arr[i]] += 1

print(count)

Solution (Python):
N=int(input())
dic={}
cnt=0
for i in range(N):
    temp=' '.join(sorted(input()))
    if temp in dic:
        dic[temp]+=1
    else:
        dic[temp]=1
for j in dic.values():
    cnt+=j*(j-1)//2
print(cnt)

Solution (Python):

import sys
input = sys.stdin.readline

from collections import Counter


def main():
    N = int(input())
    A = Counter("".join(sorted(input())) for _ in range(N))
    ans = sum(i * (i - 1) // 2 for i in A.values())
    print(ans)


if __name__ == "__main__":
    main()

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

MAP = "0123456789A"
freqs = {}
for i in range(N):
  s = input()

  template = [0 for x in range(26)]
  for j in range(len(s)):
    template[ord(s[j]) - ord("a")] += 1
  freq_str = ""
  for j in range(26):
    freq_str += MAP[template[j]]
  freqs[freq_str] = freqs.get(freq_str, 0) + 1

ans = 0
for key in freqs:
  ans += (freqs[key] * (freqs[key] - 1)) // 2
print(ans)