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

dic = {}

for _ in range(N):
  s = input()
  s = sorted(s)
  s = "".join(s)
  if s not in dic:
    dic[s] = 1
  else:
    dic[s] +=1
  
rlt = 0
for k in dic:
  rlt += dic[k]*(dic[k]-1)//2
  
print(rlt)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
a = [0]*n
for i in range(n):
    for j in range(10):
        a[i] += 10**(ord(s[i][j])-97)

a.sort()

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

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

def makeFreqTuple(s):
    freq = [0] * 26
    for c in s:
        freq[ord(c)-ord("a")] += 1
    return tuple(freq)

def C(n, k):
    numera = 1
    for i in range(n, n-k, -1):
        numera *= i
    denomi = 1
    for i in range(k, 1, -1):
        denomi *= i
    return numera // denomi

dic = defaultdict(int)
for i in range(n):
    s = input()
    t = makeFreqTuple(s)
    dic[t] += 1

ans = 0
for k, v in dic.items():
    ans += C(v, 2)
print (ans)

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

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

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
    N = int(input())
    S = sorted(["".join(sorted(input())) for _ in range(N)])
    
    ans = 0
    cnt = 0
    for i in range(1, N):
        if S[i-1] == S[i]:
            if cnt == 0:
                cnt = 2
            else:
                cnt += 1
        else:
            if cnt != 0:
                ans += cnt*(cnt-1)//2
            cnt = 0
    if cnt != 0:
        ans += cnt*(cnt-1)//2
    print(ans) 
    


    
if '__main__' == __name__:
    resolve()

Solution (Python):


if __name__ == "__main__":
    N = int(input())
    mydict = {}
    ans = 0
    for i in range(N):
        s = list(input())
        S = [str(c) for c in s]
        S.sort()

        if str(S) in mydict.keys():
            mydict[str(S)] += 1 
        else:
            mydict[str(S)] = 1


    for i in mydict.keys():
        tmp = mydict[i]
        if tmp >= 2:
            ans += tmp*(tmp-1)//2
    print(ans)

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

count = 0
dic = {}

for a in s:
    if a in dic.keys():
        count += dic[a]
        dic[a] += 1
    else:
        dic[a] = 1

print(count)

Solution (Python):
from math import factorial

n = int(input())
S = [input() for _ in range(n)]
d = dict()

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

d_comb = dict()
def fact(n):
    keys = d_comb.keys()
    if n not in keys:
        d_comb[n] = factorial(n)
    return d_comb[n]

def comb(n, r):
    if n < r:
        return 0
    f_n = fact(n)
    f_nr = fact(n - r)
    f_r = fact(r)
    return f_n // (f_nr * f_r)

ans = 0
for k in d.keys():
    ans += comb(d[k], 2)
print(ans)

Solution (Python):
def resolve():
    n=int(input())
    s={}
    for i in range(n):
        x=str(sorted(list(input())))
        if x in s.keys():
            s[x]+=1
        else:
            s[x]=1
    ans=0
    if s:
        for i in s.values():
            ans+=i*(i-1)//2
    print(ans)

if __name__ == '__main__':
    resolve()

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

Solution (Python):
import sys
from operator import itemgetter
from collections import Counter
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    N = ii()
    S = Counter()
        
    for s in [input().rstrip() for _ in range(N)]:
        s = list(s)
        s.sort()
        s = "".join(s)
        S[s] += 1

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

    print(ans)

    return

main()

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = []
for i in range(N):
	S.append(rs())

import collections
h = collections.defaultdict(int)
for s in S:
	l = [0] * 26
	for c in s:
		n = ord(c)-ord('a')
		l[n] += 1
	h[tuple(l)] += 1

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

ans = 0
for k, v in h.items():
	if v > 1:
		ans += comb(v, 2)
print(ans)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    cnt = 0
    past = {}
    for i in range(n):
        si = s[i]
        if si in past:
            past[si] += 1
        else:
            past[si] = 1
    for i in past.values():
        cnt += i*(i-1)//2
    print(cnt)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from collections import Counter

N = int(input())

lst = []

for _ in range(N):
  S = input()
  S = sorted(S)
  S = ''.join(S)
  lst.append(S)

dic = Counter(lst)

rlt = 0
for k in dic:
  rlt += (dic[k]-1)*dic[k]//2
  
print(rlt)

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

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**6 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    while True:
        if h >= mod :
            h = 0
        if hs[h][0] == 0:
            hs[h][0] += 1
            hs[h][1] += s
            break
        if hs[h][1] == s:
            hs[h][0] += 1
            break
        h += 1

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(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):
n=int(input())
dic={}
for i in range(n):
  tmp="".join(sorted(list(input().strip())))
  dic[tmp]=dic.get(tmp,0)+1
ans=0
for k in dic.keys():
  if dic[k] >= 2:
    ans+=(dic[k]*(dic[k]-1))//2
print(ans)

Solution (Python):
n=int(input())
s={}
for i in range(n):
  tmp=list(input().strip())
  tmp.sort()
  tmp="".join(tmp)
  s[tmp]=s.get(tmp,0)+1
  
ans=0
for key in s.keys():
  v=s[key]
  if v<2:
    continue
  cmb=v*(v-1)
  cmb=cmb//2
  ans+=cmb
print(ans)

Solution (Python):
import collections

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

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

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

s_dict = dict([])

for i in s:
    key = ''.join(sorted(i))
    s_dict.setdefault(key, 0)
    s_dict[key] += 1

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

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

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

s_dict = dict([])

for i in s:
    key = ''.join(sorted(i))
    try:
        s_dict[key] += 1
    except KeyError:
        s_dict[key] = 1

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

Solution (Python):

from scipy.special import comb

n, *s = open(0).read().split()
d = {}
for i in s:
    l = "".join(sorted(j for j in i))
    if l in d:
        d[l] += 1
    else:
        d[l] = 1
print(sum(comb(i, 2,exact=True) for i in d.values()))

Solution (Python):
import collections
def main4():
    dd = collections.defaultdict(int)
    n = int(input())
    res = 0
    for i in range(n):
        s = input()
        a = sorted(s)
        dd[''.join(a)]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)


if __name__ == '__main__':
    main4()

Solution (Python):
import collections
def main4():
    n = int(input())
    l = []
    for i in range(n):
        s = input()
        l.append((sorted(s)))
    l.sort()
    dd = collections.defaultdict(int)
    k = []
    for i in range(n):
        k.append(''.join(l[i]))
    res = 0
    for i in range(n):
        dd[k[i]]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main4()

Solution (Python):
from collections import defaultdict

n=int(input())
h=defaultdict(int)
for i in range(n):
  s=list(input().strip())
  s.sort()
  h["".join(s)]+=1

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

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

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

ans = 0
for _ in range(n):
    s = input()
    s = ''.join(sorted(s))
    s_cnt.setdefault(s,0)
    ans += s_cnt[s]
    s_cnt[s] += 1

print(ans)

Solution (Python):


import sys
stdin = sys.stdin
from collections import Counter

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    l = list()
    for i in range(n):
        s = ns()
        l.append("".join(sorted(s)))
    ans = 0
    for i in Counter(l).values():
        ans += (i * (i-1))//2
    print(ans)

if __name__ == "__main__":
    main()

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

N = int(input())
dic_s = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s in dic_s:
        dic_s[s] += 1
    else:
        dic_s[s] = 1
counter = 0
for key,value in dic_s.items():
    if value >1:
        counter += combinations_count(value,2)
print(counter)

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

s = []

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

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
N = int(input())

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

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

print(ans)

Solution (Python):
from collections import defaultdict

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

ctr = defaultdict(int)

for i in range(N):
    tmp = [0] * 26
    for j in range(10):
        tmp[ord(S[i][j]) - ord("a")] += 1
    ctr[tuple(tmp)] += 1

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

Solution (Python):
from collections import Counter

N=int(input())

dic={}
ans=0

for i in range(N):
    si=input()
    
    
    
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]+=1
    else:
        dic[sorted_s]=1

print(ans)

Solution (Python):
from collections import Counter

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

ans=0

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

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

n=int(input())
dic=[]
for i in range(n):
    dic.append(sorted(list(input().rstrip())))
dic=sorted(dic)

from math import factorial

ans=0
temp=1
for i in range(1,n):
    if dic[i]==dic[i-1]:
        temp+=1
    else:
        if temp>=2:
            ans+=(factorial(temp)//(2*factorial(temp-2)))
        temp=1

if temp>=2:
    ans+=(factorial(temp)//(2*factorial(temp-2)))

print(ans)

Solution (Python):
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = [sorted(input()) for i in range(n)]
s.sort()

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

Solution (Python):
from collections import defaultdict
import math

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

def main():
    N = int(input())
    S = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(list(input())))
        if s in S:
            S[s] += 1
        else:
            S.update({s:0})
    cnt = 0
    for k,v in S.items():
        if v == 0:
            continue
        elif v == 1:
            cnt += v
        else:
            cnt += combinations_count(v+1,2)
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):

import math
def nCr(n,r):
    if n < 2:
        return 0
    ans = int(math.factorial(n)/(math.factorial(n-r)*math.factorial(r)))
    return ans 
import collections
N = int(input())
L = []
for i in range(N):
    S = input()
    S = sorted(S)
    L.append(str(S))
C = collections.Counter(L)
ans = 0
for i in C.values():
    ans += nCr(i,2)
print(ans)

Solution (Python):
N = int(input())
S = []
for _ in range(N):
    S.append(input())
for i in range(N):
  S[i] = sorted(S[i])
  S[i] = ''.join(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 = []
for i in range(N):
  tmp = list(input())
  tmp.sort()				
  s.append(''.join(tmp))	
s.sort()

i, j = 0, 1
count = 0
total = 0
while j < N:
  while s[i] == s[j]:
    count += 1
    j += 1
    if j == N:
      break
  
  if count >= 1:
    tmp1, tmp2 = 1, 2
    for k in range(count+1, count+1-2, -1):
      tmp1 *= k
    total += int(tmp1/tmp2)
  i = j
  j += 1
  count = 0
print(total)

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

i, j = 0, 1
count = 0
total = 0
while j < N:
  while s[i] == s[j]:
    count += 1
    j += 1
    if j == N:
      break
  
  if count == 1:
    total += 1
  elif count > 1:
    tmp1, tmp2 = 1, 2
    for k in range(count+1, count+1-2, -1):
      tmp1 *= k
    total += int(tmp1/tmp2)
  i = j
  j += 1
  count = 0

print(total)

Solution (Python):
def ra(a): 
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll

n=int(input())
print(sum([i*(i-1)//2 for i in ra(sorted([''.join(sorted(i)) for i in [input() for i in range(n)]]))]))

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

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

for i in range(n):
    s[i] = sorted(s[i])
    s[i] = "".join(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):
import collections

ans=0
dic={}
n=int(input())
for i in range(n):
  s=input()
  sl=[i for i in s]
  sl.sort()
  ss=tuple(sl)

  if ss not in dic:
    dic[ss]=1
  else:
    ans+=dic[ss]
    dic[ss]+=1

print(ans)

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

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
n = int(input())
cnt = 0
for _ in range(n):
  s = "".join(sorted(input()))
  cnt += d[s]
  d[s] += 1
print(cnt)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
n = int(input())
cnt = 0
for _ in range(n):
  a = input()
  b = ''
  for i in sorted(a):
    b += i
  cnt += d[b]
  d[b] += 1
print(cnt)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
n = int(input())
for _ in range(n):
  a = input()
  g = [0]*26
  for i in a:
    g[ord(i)-97]+=1
  b = ''
  for i in g:
    b+=str(i)
  d[b]+=1
cnt = 0
for k,v in d.items():
  if v > 1:
    cnt += v*(v-1)//2
print(cnt)

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

def main():
    n = int(input())
    string = dict()
    ans = 0
    for _ in range(n):
        s = ''.join(sorted(input()))
        if s in string:
            string[s] += 1
        else:
            string[s] = 1
    for i in string.values():
        if i > 1:
            ans += math.factorial(i)//(2*math.factorial(i-2))
    print(ans)

if __name__ == '__main__':
    main()

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

d = defaultdict(int)
for a in s:
  d[a]+=1
c=0
for a in d.values():
  if a>1:
    c+=a*(a-1)//2
print(c)

Solution (Python):
from collections import Counter
N = int(input())
d = dict()

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

Solution (Python):
import collections


def main():
    N = int(input())
    table = [''.join(sorted(list(input()))) for _ in range(N)]
    sort_table = set(table)
    cnt_table = collections.Counter(table)
    ans = 0
    for i in sort_table:
        num_of_i = cnt_table[i]
        if num_of_i <= 1:
            continue
        x = (num_of_i * (num_of_i - 1)) // 2
        ans += x

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections
import math
def Comb(N,R):
    return math.factorial(N)//(math.factorial(N-R)*math.factorial(R))

N = int(input())
S = ['']*N
for T in range(0,N):
    S[T] = ''.join(sorted(input()))
Count = list(collections.Counter(S).values())
Sum = 0
for TT in range(0,len(Count)):
    if Count[TT]>=2:
        Sum += Comb(Count[TT],2)
print(Sum)

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

for _ in range(n):
    s = input()
    s = ''.join(sorted(s))
    s_cnt.setdefault(s,0)
    s_cnt[s] += 1

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

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
count_list = []
for i in range(n):
    s = input()
    c = sorted(Counter(s).items(), key = lambda x:x[0])
    tmp = ""
    for j in range(len(c)):
        tmp += c[j][0]
        tmp += str(c[j][1])
    count_list.append(tmp)

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

print(ans)

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

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

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

def combination(i):
    return factorial(i) // (factorial(i-2) * factorial(2))

cnt = Counter(s)
ans = 0
for i in cnt.values():
    if i == 1:
        pass
    else:
        ans += combination(i)
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
str_list = []
count_list = []
S = [''.join(sorted(list(input()))) for _ in range(N)]
count = Counter(S)
ans = 0

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

Solution (Python):
n = int(input())
dic = {}
for i in range(n):
  temp = 0
  s = input()
  for j in s:
    temp += (12 ** (ord(j) - ord('a') + 1))
  dic.setdefault(temp, 0)
  dic[temp] += 1

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

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

alpha2num = lambda c: ord(c) - ord('a')

S_num_list=[]

for n in range(N):
    S_=input()
    S_num=[0]*26
    for s in S_:
        S_num[alpha2num(s)] += 1
    S_num_list.append(''.join(map(str,S_num)))
    
S_counter=Counter(S_num_list)

ans=0
for s in S_counter.keys():
    s_num = S_counter[s]
    s_combination_num = int((s_num*(s_num-1))/2)
    ans += s_combination_num
print(ans)

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

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

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

Solution (Python):
n=int(input())
list1=[]
def apl1(l1):
    list1.append(l1)
for i in range(n):
    apl1(str(sorted(list(input()))))
list1.sort()
str1=list1[0]
ans=0
num=0
def num_1(num1):
    return ((num1+1)*num1)//2
for i in range(1,n):
    if str1==list1[i]:
        num+=1
    else:
        ans+=num_1(num)
        str1=list1[i]
        num=0
if num>=1:
    ans+=num_1(num)
print(ans)

Solution (Python):

def main():
    import collections


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

if __name__ == '__main__':
    main()

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

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

Solution (Python):


import math

N = int(input())

s_dic = {}
s_set = set()

for i in range(N):
    s = input()

    s = ''.join(sorted(s))

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

    else:
        s_set.add(s)
        s_dic[s] = 1


result = 0

for val in s_dic.values():

    if val > 1:
        result += int((val * (val - 1)) / 2)

print(result)

Solution (Python):
n = int(input())
dic = dict()
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)

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

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

print(count)

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

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

Solution (Python):
from collections import Counter
import math
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 k,v in C.items():
    ans+=v*(v-1)//2
print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=[]
for i in range(n):
    w=sorted(list(input()))
    s.append("".join(w))
l=list(Counter(s).values())
ans=0
for i in l:
    ans+=i*(i-1)//2
print(ans)

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    ans = 0
    d = defaultdict(int)
    for s in S:
        s = ''.join(sorted(s))
        if s in d:
            ans += d[s]
        d[s] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    d = defaultdict(int)
    for s in S:
        d[''.join(sorted(s))] += 1

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    d = defaultdict(int)
    for s in S:
        c = [0] * 26
        for l in s:
            c[ord(l) - 97] += 1
        d[tuple(c)] += 1

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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

Solution (Python):
c,a={},0
for _ in range(int(input())):
  s=tuple(sorted(input()))
  c[s]=c.get(s,-1)+1
  a+=c[s]
print(a)

Solution (Python):
c={}
for _ in range(int(input())):
  s=tuple(sorted(input()))
  c[s]=c.get(s,0)+1
print(sum(v*(v-1)//2 for v in c.values()))

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

Solution (Python):
import collections
n=int(input())
print(int(sum((i*(i-1)/2)for i in collections.Counter([str(sorted(input()))for i in range(n)]).values())))

Solution (Python):
import collections
N=int(input())
ss=['' for i in range(N)]

for i in range(N):
    ss[i]=''.join(sorted(str(input())))

cc=collections.Counter(ss)
ans=0
values, counts = zip(*cc.most_common())
counts=list(counts)

for i in range(len(counts)):
    if counts[i]==1:
        break
    else:
        ans+=counts[i]*(counts[i]-1)/2

print(int(ans))

Solution (Python):

def mi(): return map(int,input().split())
def lmi(): return list(map(str,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
dic_s={}
for i in range(n):
  s_=list(input())
  s__=sorted(s_)
  
  s=''.join(s__)
  if s in dic_s.keys():
    dic_s[s]+=1
  else:
    dic_s.setdefault(s,1)

  
cnt=0

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

print(cnt)

Solution (Python):
from collections import defaultdict

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

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

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

print(count)

Solution (Python):
N=int(input())
S=[]
for _ in range(N):
  s=list(input())
  s.sort()
  S.append("".join(s))
from math import factorial
def C(n, r):
  return factorial(n)//(factorial(r)*factorial(n-r))
S.sort()
tmp=list(set(S))
tmp.sort()
j=0
num=0
ans=0
S.append("123")
for i in range(N+1):
  if tmp[j]==S[i]:
    num+=1
  else:
    if num>1:
      ans+=C(num,2)
    num=1
    j+=1
print(ans)

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):
import math
from itertools import groupby

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
sizes = [len(list(v)) for k, v in groupby(sorted(S))]


def combinations_count(n, r):
    if n == 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ans = sum([combinations_count(size, 2) for size in sizes])
print(ans)

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




dic={}
res=0
for i in range(n):
    s=list(input())
    s="".join(sorted(s))
    count=dic.get(s,0)
    if count>0:
        res+=count
    dic[s]=count+1
print(res)

Solution (Python):
n = int(input())
dict = {}
for _ in range(n):
    s = [x for x in input()]
    s.sort()
    s = "".join(s)
    dict[s] = dict.get(s, 0) + 1
ans = 0
for k in dict:
    v = dict[k]
    ans += int(v * (v-1) /2)
print(ans)

Solution (Python):
from collections import defaultdict

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

    ans = 0

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

    print(ans)







if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
from collections import Counter


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

c = Counter(s)
ans = 0

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

print(ans)

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

d=defaultdict(int)
for i in range(n):
    s=input()
    sorted_list=sorted(s)
    s="".join(sorted_list)
    d[s]+=1
count=0
for i,j in d.items():
    count+=j*(j-1)//2

print(count)