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

l = []
for i in range(N):
    s = input()
    s = sorted(s)
    l.append("".join(s))
    
import collections

c = collections.Counter(l)

issubclass(type(c), dict)
C = list(c.values())


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

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

c = {}
for i in s:
  x = ''.join(sorted(i))
  if x in c:
    c[x] += 1
  else:
    c[x] = 1

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

print(int(ans))

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

Solution (Python):
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

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

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

Solution (Python):



import collections

n = int(input())

s_sorted = [''.join(sorted(input())) for i in range(n)]


anagram_list = collections.Counter(s_sorted)

count = 0


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

print(count)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

n = int(input())

d = {}

for i in range(n):
    t = input()
    t = ''.join(sorted(t))
    d[t] = d.get(t,0) + 1
        
ans = 0

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

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

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

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

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

words = {}
anagrams = 0

for i in range(n):
    word = "".join(sorted(input()))
    if word not in words:
        words[word] = 1
    else:
        anagrams += words[word]
        words[word] += 1

print(anagrams)

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())
dictionary={}
count=0
for i in range(N):
    s=tuple(sorted(input()))
    if s in dictionary:
        dictionary[s]+=1
        count+=dictionary[s]
    else:
        dictionary[s]=0
print(count)

Solution (Python):
N = int(input())
S = ["".join(sorted(input())) for i 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):
n=int(input())
ans=0
s=[[x for x in input()] for i in range(n)]

dic={}
for i in s:
  temp=tuple(sorted(i))
  if temp in dic:
    ans+=dic[temp]
    dic[temp]+=1
  else:
    dic[temp]=1
print(ans)

Solution (Python):
n = int(input())
save = [-1]*(n+1)

def aC2(a):
    if(save[a]!=-1):
        return save[a]
    ans = 1
    for i in range(a-1,a+1):
        ans *= i
    ans //=2
    save[a] = ans
    return ans

dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if(dic.get(s) is None):
        dic[s] = 1
    else:
        dic[s] += 1

ans = 0
for x in dic.values():
    if(x==0 or x==1):
        continue
    ans += aC2(x)

print(ans)

Solution (Python):

from collections import Counter
n = int(input())
s = [0]*n
a = [[0 for l in range(26)] for m in range(n)]
for i in range(n):
    s[i] = input()
for j in range(n):
    a[j][0] = s[j].count('a')
    a[j][1] = s[j].count('b')
    a[j][2] = s[j].count('c')
    a[j][3] = s[j].count('d')
    a[j][4] = s[j].count('e')
    a[j][5] = s[j].count('f')
    a[j][6] = s[j].count('g')
    a[j][7] = s[j].count('h')
    a[j][8] = s[j].count('i')
    a[j][9] = s[j].count('j')
    a[j][10] = s[j].count('k')
    a[j][11] = s[j].count('l')
    a[j][12] = s[j].count('m')
    a[j][13] = s[j].count('n')
    a[j][14] = s[j].count('o')
    a[j][15] = s[j].count('p')
    a[j][16] = s[j].count('q')
    a[j][17] = s[j].count('r')
    a[j][18] = s[j].count('s')
    a[j][19] = s[j].count('t')
    a[j][20] = s[j].count('u')
    a[j][21] = s[j].count('v')
    a[j][22] = s[j].count('w')
    a[j][23] = s[j].count('x')
    a[j][24] = s[j].count('y')
    a[j][25] = s[j].count('z')
counter = Counter(tuple(x) for x in a)
k = list(counter.values())
ans = 0
for y in k:
    ans += (y*(y-1))//2
print(ans)

Solution (Python):
N=int(input())
s=[]
for i in range(N):
  s.append(sorted(list(input())))
s.sort()
ans=0
ren=1
for i in range(1,N):
  if s[i]==s[i-1]:
    ren+=1
  else:
    ans+=ren*(ren-1)//2
    ren=1
ans+=ren*(ren-1)//2
print(ans)

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

num = {}

for i in range(n):
    seq = input()
    seq = ''.join(sorted(seq))
    if seq in num:
        num[seq] += 1
    else:
        num[seq] = 1

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

print(ans)

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

hashtable = {}

for x in S:
    hashtable.setdefault(x, 0)
    hashtable[x] += 1

sumS = 0
for y in hashtable.values():
    sumS += y * (y - 1) // 2
print(sumS)

Solution (Python):
from collections import Counter
n = int(input())
counter=Counter(["".join(sorted(input())) for _ in range(n)])

from math import factorial
def combi(n,r):
    return factorial(n)//(factorial(r)*factorial(n-r))
    
print(sum([combi(c,2) for c in counter.values() if c>1]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



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

dic = defaultdict(int)
for x in s:
	dic[x] += 1

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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



N = INT()
s = [str(sorted(list(input()))) for _ in range(N)]

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

print(ans)

Solution (Python):
import collections
N = int(input())
S = [''.join(sorted(list(input()))) for _ in range(N)]
C = collections.Counter(S)
count = 0
for key in C.keys():
    c = C[key]
    if c > 1:
        count += c*(c-1)//2
print(count)

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

ans = 0
count = 1
pre = S[0]
for i in range(1, N):
    if S[i] != pre:
        ans += count*(count-1)//2
        count = 1
        pre = S[i]
    else:
        count += 1

ans += count*(count-1)//2
print(ans)

Solution (Python):
n = int (input())
s = []
cnt = [0]* n
for i in range(n):
    a = list(input())
    a.sort()
    s.append(''.join(a))
ans = 0
s.sort()
ren = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        ans+=1+ren
        ren +=1
    else:
        ren = 0
print(ans)

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

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

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

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

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

Solution (Python):
from collections import Counter
N = int(input())
S = [list(input()) for _ in range(N)]
for i in range(N):
    S[i].sort()
    S[i] = ''.join(S[i])
C = Counter(S)
ans = 0
for i in C.values():
    ans += i*(i-1)//2
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline









N = int(input())
S = [list(input().rstrip()) for _ in range(N)]

from collections import defaultdict
d = defaultdict(int)

for s in S:
    s.sort()
    d["".join(s)] += 1

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

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

N = int(input().rstrip())
S = []
for s in range(N):
    S.append(sorted(input().rstrip()))
S = sorted(S)
ans = 0
ren = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += ren
        ren += 1
    else:
        ren = 1

print(ans)

Solution (Python):
from collections import defaultdict


def main():
    N = int(input())
    d = defaultdict(int)
    s = 0
    for i in range(N):
        d["".join(sorted(input()))] += 1

    for k in d.keys():
        s += d[k]*(d[k]-1)/2

    print(int(s))


if __name__ == '__main__':
    main()

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

words = {}
anagrams = 0

for i in range(n):
    word = "".join(sorted(input()))
    if word not in words:
        words[word] = 1
    else:
        anagrams += words[word]
        words[word] += 1

print(anagrams)

Solution (Python):

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

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

dic = {}
ans = 0

for i in range(N):
    if not s[i] in dic:
        dic[s[i]] = 0
    dic[s[i]] += 1

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

print(ans)

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


count=0
n=1
for i in range(1,N):
    if S[i-1] == S[i]:
        n+=1
    else:
        count+= n*(n-1)*0.5
        n=1
count+=n*(n-1)*0.5
print(int(count))

Solution (Python):
import sys
from scipy.misc import comb

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() 
ni = lambda: int(readline().rstrip()) 
nm = lambda: map(int, readline().split()) 
nl = lambda: list(map(int, readline().split())) 

n = ni()
str_list = [''.join(sorted(input())) for _ in range(n)]

check = ''
cnt = 1
ans = 0
for s in sorted(str_list):
    if s == check:
        cnt += 1
    else:
        if cnt >= 2:
            ans += comb(cnt, 2, exact=True)
        cnt = 1
    check = s
if cnt >= 2:
    ans += comb(cnt, 2, exact=True)
print(ans)

Solution (Python):

import sys
import collections

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = int(readline())
    s_list = [''.join(sorted(s.rstrip().decode())) for s in readlines()]
    counter = collections.Counter(s_list)
    ans = 0
    for v in counter.values():
        if v != 1:
            ans += v * (v - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
N = int(input())
dict = defaultdict(int)
ans = 0
for i in range(N):
    s = ''.join(sorted(input()))
    ans += dict[s]
    dict[s] += 1
print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
new_s = []
cnt = {}
ans = 0

for i in s:
    new_s.append(str(sorted(i)))

for i in new_s:
    if i in cnt.keys():
        cnt[i] += 1
    else:
        cnt[i] = 1
for v in cnt.values():
    ans += v * (v-1) // 2

print(ans)

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

for _ in range(N):
    s = "".join(sorted(input()))
    try:
        ans += unique_string[s]
        unique_string[s] += 1
    except KeyError:
        unique_string[s] = 1

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

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)


from collections import Counter,deque,defaultdict





n=n0()
s=s2(n)
d=defaultdict(int)

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

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)


from collections import Counter,deque,defaultdict





n=n0()
s=s2(n)
d=defaultdict(int)

for line in s:
    a=[0]*26
    c=set((Counter(line)).items())
    for t in c:
        a[ord(t[0])-97]=t[1]
    d[tuple(a)]+=1

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

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

Solution (Python):
import collections
N=int(input())
s=[input() for i in range(N)]
S=[]
ans=0
for i in s:
  a=sorted(i)
  a="".join(a)
  S.append(a)
c=collections.Counter(S)
d=list(map(int,c.values()))
for i in d:
  ans+=i*(i-1)/2
print(int(ans))

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

S=set(s)

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

from collections import Counter

ans=0
l=Counter(s)
for x in S:
    a=l[x]
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)

Solution (Python):
import sys
import collections


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


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


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
s = []
ans = 0
for i in range(N):
    s.append(''.join(sorted(S())))

c = collections.Counter(s)

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

Solution (Python):
from math import factorial
def comb(n,r):
  return factorial(n)//factorial(n-r)//factorial(r)
N=int(input())
S=[]
for i in range(N):
  s=list(input())
  s.sort()
  S+=[s]
S.sort()  
ans=0
anssub=1
for i in range(N-1):
  if S[i]==S[i+1]:
    anssub+=1
  else:
    if anssub!=1:
      ans+=comb(anssub,2)
    anssub=1
  if i==N-2 and anssub!=1:
    ans+=comb(anssub,2)
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
s = [list(input()) for i in range(0,N,1)]
for i in range(0,N,1):
    s[i].sort()
S = ["".join(s[i]) for i in range(0,N,1)]

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

Solution (Python):
from collections import defaultdict

N = int(input())
S = defaultdict(int)
ans = 0
for _ in range(N):
    s = input()
    sl = []
    for n in s:
        sl.append(n)
    sl.sort()
    s = ''.join(sl)
    S[s] += 1

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

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

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

res = 0
for v in dic.values():
  if v >= 2:
    res += v*(v-1)
print(res//2)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
s_dic = {}
for _ in range(N):
    s_list = list(input())
    s_list.sort()
    s = ''.join(s_list)

    if s in s_dic:
        s_dic[s] += 1
    else:
        s_dic[s] = 1

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

Solution (Python):
import sys
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


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
s_dic = {}
for _ in range(N):
    s_list = list(input())
    s_list.sort()
    s = ''.join(s_list)

    if s in s_dic:
        s_dic[s] += 1
    else:
        s_dic[s] = 1

ans = 0
for k, v in s_dic.items():
    if v >= 2:
        ans += cmb(v, 2)
print(ans)

Solution (Python):
import collections

d = {}
n = int(input())
ans = 0
for i in range(n):
    st = list(input())
    st.sort()
    s = ''.join(st)
    m = d.get(s,False)
    if m:
        ans += m
        d[s] = m+1
    else:
        d[s] = 1 
    
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
s = []

for i in range(n):
    temp = sorted(input())
    temp = ''.join(temp)
    s.append(temp)

s = Counter(s)

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

print(result)

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

d = {}
for i in s:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

ans = 0
for i in d:
  t = d[i]
  ans += t*(t-1)//2
print(ans)

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

w = Counter(s)
ans = 0
for i in w:
  t = w[i]
  ans += t*(t-1)//2
print(ans)

Solution (Python):
import sys


n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(sys.stdin.readline()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

print(ans)

Solution (Python):



from collections import Counter

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

C = Counter(S)

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

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter
def main():
    n = int(readline())
    S = []
    for i in range(n):
        S.append(''.join(sorted(readline().rstrip().decode())))
    ans = 0
    for v in Counter(S).values():
        ans += v*(v-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import collections
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
c = collections.Counter(s)

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

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
    s = str(input())
    s = ''.join(sorted(s))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
cnt = 0
for k, v in d.items():
    if v != 1:
        cnt += v * (v - 1) // 2
print(cnt)

Solution (Python):
import itertools
import collections
from collections import Counter
n=int(input())
k=[]
t=0
for i in range(n):
    p=input()
    k.append(tuple(sorted(p)))
k=Counter(k)
v,c=zip(*k.most_common())
c=list(c)
for i in range(len(c)):
    n=c[i]
    t+=n*(n-1)/2
print(int(t))

Solution (Python):
import itertools
import collections
from collections import Counter
n=int(input())
k=[]
t=0
for i in range(n):
    p=input()
    k.append(sorted(p))
for i in range(n):
    k[i]=tuple(k[i])
k=Counter(k)
v,c=zip(*k.most_common())
c=list(c)
for i in range(len(c)):
    n=c[i]
    t+=n*(n-1)/2
print(int(t))

Solution (Python):
from collections import defaultdict
n = int(input())
dic_sorted_s = defaultdict(int)
count = 0
for i in range(n):
    s = input()
    str_sorted_s = ''.join(sorted(s))
    count += dic_sorted_s[str_sorted_s]
    dic_sorted_s[str_sorted_s] += 1
print(count)

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

print(ans)

Solution (Python):
import math

n=int(input())

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

ans=0
for n in dic.values():
    if n>1:
        ans += math.factorial(n) // (math.factorial(n-2) * math.factorial(2))


print(ans)

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

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():
  ans+=x*(x-1)//2
print(ans)

Solution (Python):
n = int(input())
cnt = {}
for _ in range(n):
    sorted_s = "".join(sorted(input()))
    cnt.setdefault(sorted_s, 0)
    cnt[sorted_s] += 1
ans = 0
for v in cnt.values():
    if v < 2: continue
    ans += int(v * (v - 1) / 2)
print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
d = DD(int)

for _ in range(N):
  k = list(S())
  k.sort()
  k = tuple(k)
  d[k] += 1

keys  = [k for k in d]
print(sum(d[k]*(d[k]-1)//2 for k in keys))

Solution (Python):
n=int(input())
ans=dict()
for i in range(n):
  d=list(input())
  d.sort()
  s="".join(d)
  if not(s in ans):
    ans[s]=1
  else:
    ans[s]+=1
anss=0
for i in ans:
  anss+=((ans[i]*(ans[i]-1))//2)
print(anss)

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

d = {}
ans = 0
for i in range(n):
    s = S[i]
    s = list(s)
    s.sort()
    s = ''.join(s)
    if s in d:
        ans += d[s]
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
print(ans)

Solution (Python):
from collections import Counter
import math
def combination2(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

N = int(input())
l = []
for _ in range(N):
    tmp = input()
    tmp = sorted(tmp)
    l.append(''.join(tmp))

l = Counter(l)
ans = 0
for key, value in l.items():
    if value >= 2:
        ans += combination2(value)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

dic = defaultdict(int)

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

print (ans)

Solution (Python):
n=int(input())
d={}
for i in range(n):
    si=''.join(list(sorted(input())))
    d[si]=d.get(si, 0)+1

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

Solution (Python):
N = int(input())
C = {}
for i in range(N):
    s = input().strip()
    s = "".join(sorted(s))
    if s not in C:
        C[s] = 0
    C[s] += 1
cnt = 0
for x in C:
    n = C[x]
    cnt += (n*(n-1))//2
print(cnt)

Solution (Python):
n = int(input())
from collections import defaultdict
dic = defaultdict(int)
for i in range(n):
    s = "".join(list(sorted(input())))
    dic[s] += 1

cnt = 0
for k,v in dic.items():
    cnt += v*(v-1)//2
print(cnt)

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

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

cnt = {}
for i, si in enumerate(s):
    cnt_tmp = {}
    for j, sij in enumerate(si):
        key = str(sij)
        cnt_tmp.setdefault(key, 0)
        cnt_tmp[sij] += 1
    
    key_si = ''
    for key, val in sorted(cnt_tmp.items()):
        key_si += '{0}_{1}/'.format(key, val)
    
    cnt.setdefault(key_si, 0)
    cnt[key_si] += 1

ans = 0
for key, val in cnt.items():
    ans += val * (val - 1) // 2

print(ans)

Solution (Python):
N = int(input())
from collections import Counter
ctr = Counter()
for i in range(N):
    s = input()
    h = hash(tuple(sorted(s)))
    ctr[h] += 1
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Solution (Python):
from collections import Counter

N, *S = open(0).read().split()
S = [''.join(sorted(s)) for s in S]
C = Counter(S)

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

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

N = int(input())
cnt = defaultdict(int)
ans = 0

for _ in range(N):
    s = input()[:-1]
    s = list(s)
    s.sort()
    s = ''.join(s)
    ans += cnt[s]
    cnt[s] += 1

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
counter = Counter()

for i in range(N):
    s = input()
    lst = []
    for c in s:
        lst.append(c)
    lst.sort()
    lst = "".join(lst)
    counter[lst] += 1

cnt = 0

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

print(cnt)

Solution (Python):
def main():
    word = {}
    n = int(input())
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in word:
            word[s] += 1
        else:
            word[s] = 1
    answer = 0
    for cnt in word.values():
        answer += cnt * (cnt - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
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)