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 defaultdict

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

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

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

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

    s_dict = {}
    count = 0
    
    for i in range(n):
        s = sorted(input())
        _s = "".join(s)
        
        if not _s in s_dict:
            s_dict[_s] = 1
        else:
            count += s_dict[_s]
            s_dict[_s] += 1
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    sd = {}
    ans = 0
    for _ in range(N):
        si = ''.join(sorted(input().strip()))
        if not si in sd:
            sd[si] = 1
        else:
            ans += sd[si]
            sd[si] += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):


N = int(input())

sd = {}
ans = 0

for _ in range(N):
    inp = input()
    si = ''.join(sorted(inp))
    
    if not si in sd:
        sd[si] = 1
    else:
        ans += sd[si]
        sd[si] += 1

print(ans)

Solution (Python):
import collections
N = int(input())
stock = dict()
ans = 0
for i in range(N):
    c="".join(sorted(input()))
    if c in stock:
        ans += stock[c]
        stock[c] += 1
    else:
        stock[c] = 1
print(ans)

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

for i in range(N):
  letter = input()
  tmp = []
  for k in range(10):
    tmp.append(letter[k])
    
  tmp.sort()
  letter = ''.join(tmp)
  if letter in ana_list:
    ana_list['{}'.format(letter)] += 1
  else:
    ana_list['{}'.format(letter)] = 1

num_list = list(ana_list.values())

ans = 0
for i in range(len(num_list)):
  if num_list[i] >= 2:
    ans += num_list[i] * (num_list[i] - 1) / 2
    
print(int(ans))

Solution (Python):

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    D=defaultdict(int)
    for _ in range(n):
        tup=tuple(sorted(input()))
        D[tup]+=1

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

    print(ans)
resolve()

Solution (Python):
import bisect
import heapq
from collections import Counter

N = int(input())
S = []
for n in range(N):
    string = ''.join(sorted(input()))
    S.append(string)
ans = 0
counter_s = Counter(S)
for key, value in counter_s.items():
    if value >= 2:
        ans += value * (value - 1) // 2
print(ans)

Solution (Python):
from collections import defaultdict

import itertools


def comb_list(seq:list, n:int):
    return list(itertools.combinations(seq, n))


def comb_num(a, b):
    if a - b < b: b = a - b
    if b == 0: return 1
    if b == 1: return a

    numerator = [a - b + k + 1 for k in range(b)]
    denominator = [k + 1 for k in range(b)]

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

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

    return result

N = int(input())

cnt = defaultdict(int)
for i in range(N):
    s = input()
    s = sorted(s)
    cnt[str(s)] += 1

ans = 0
for c in cnt.values():
    if c==1:
        continue
    ans += comb_num(c, 2)
print(ans)

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

Solution (Python):
from collections import Counter

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

for i in range(N):
    s = "".join(sorted(input()))
    A.append(s)

C = Counter(A)
ans=0

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

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A = [0]*N

for i in range(N):
    
    string = input()
    flag = True
    for j in range(10):
        A[i]+=10**(ord(string[j])-ord('a'))
        if(j<9):
            if(string[j]!=string[j+1]):
                flag = False
    if flag:
        A[i] = (ord(string[0])-ord('a')+1)*(-1)
    
C = Counter(A)
ans=0

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

print(ans)

Solution (Python):
from collections import Counter

n = int(input()) 
S = [''.join(sorted(input())) for i in range(n)] 
counter = Counter(S) 

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

print(ans)

""""
l = []
for i in range(n):
    l.append(input()) 

def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

def verify_anagrams(first_word, second_word):
    return get_counter(first_word) == get_counter(second_word)

count =0 
for i in range(n):
    for j in range(i+1,n):
        if verify_anagrams(l[i],l[j])==True:
            count += 1


print(count)


"""

Solution (Python):
from collections import Counter

N = int(input())

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

T=[''.join(sorted(S[x]))for x in range (N)]

count = Counter(T)

ans = sum(x*(x-1)//2 for x in count.values())
print(ans)

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

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

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

Solution (Python):
from collections import Counter
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
S_cnt = Counter(S).values()
cnt=0
for s in S_cnt:
    for i in range(s):
        cnt+=i

print(cnt)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 +10 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase


input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
mp=defaultdict(int)
t=[]
for i in range(n):
    s=StoI()
    s.sort()
    tmp=0
    for i in s:
        tmp=tmp*100+i
    t.append(tmp)
    
    
c=Counter(t)

ans=0
for i,j in c.items():
    ans+=j*(j-1)//2
print(ans)

Solution (Python):
from collections import Counter
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    c = Counter([''.join(sorted(input())) for _ in range(n)]).values()
    print(sum([i * (i - 1) // 2 for i in c]))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import Counter

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

counter = Counter(S)

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

Solution (Python):
n = int(input())
ana_map = {}
for i in range(n):
    s = input()
    bucket = [0 for _ in range(26)]
    
    for c in s:
        bucket[ord(c) - ord('a')] += 1
    
    if(ana_map.get(str(bucket)) is None): ana_map[str(bucket)] = 1
    else: ana_map[str(bucket)] += 1

res = 0
for key in ana_map.keys():
    res += ana_map[key] * (ana_map[key]-1) / 2
print(int(res))

Solution (Python):

import sys
import math
def combinations_count(n, r):
    if n<r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, s: "List[str]"):
    s_dict = {}    
    for i in range(N):
        ss = ''.join(sorted(list(s[i])))
        if s_dict.get(ss) == None:
            s_dict[ss] = 1
        else:
            s_dict[ss] += 1
    answer = 0
    for _,value in s_dict.items():
        answer += combinations_count(value,2)


    print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    s = [next(tokens) for _ in range(N)]  
    solve(N, s)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    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())
strings = []
for i in range(n):
    s = sorted(input().strip())
    s = ''.join(s)
    strings.append(s)

counts = defaultdict(int)

for s in strings:
    counts[s] += 1

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

print(comb)

Solution (Python):
n = int(input())
a = 0
input_list = []
while a < n:
    ant = input()
    input_list.append(ant)
    a += 1
l={}
for i in range(len(input_list)):
    l[i] = list(input_list[i])
    l[i].sort()
l_dic = {}
ans = 0
for i in range(len(l)):
    try:
        ans += l_dic[str(l[i])]
        l_dic[str(l[i])] += 1
    except:
        l_dic[str(l[i])] = 1
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
ss = ["".join(sorted(s[i])) for i in range(n)]
d = Counter()
ans = 0
for i in range(n):
  t = ss[i]
  if t in d:
    ans += d[t]
  d[t] += 1
  
print(ans)

Solution (Python):


from collections import Counter





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

counter = Counter(s)


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

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

S = []

a = ord("a")
for i in range(N):
    s = list(input())
    s.sort()
    s_= "".join(s)
    S.append(s_)
S.sort()

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

print(ans)

Solution (Python):
from collections import Counter

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    cnt = 0
    sorted_s_count = collections.defaultdict(int)
    for _ in range(N):
        s = S()
        s = ''.join(sorted(s))
        if s in sorted_s_count:
            cnt += sorted_s_count[s]
        sorted_s_count[s] += 1
    print(cnt)
main()

Solution (Python):
from collections import Counter
n=int(input())
d=Counter()
ans=0
for i in range(n):
    t=str("".join(sorted(input())))
    if t in d:
        ans+=d[t]
    d[t]+=1
print(ans)

Solution (Python):
from itertools import groupby
n=int(input())
l=[]
for _ in range(n):
  s=input()
  s=''.join(sorted(s))
  l.append(s)
l.sort()
c=0
for i,j in groupby(l):
  z=len(list(j))
  c=c+(z*(z-1)//2)
print(c)

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

print(count)

Solution (Python):
import collections as cl
import math
N=int(input())

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

result=list(cl.Counter(result_).values())

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

ans=0
for j in range(len(result)):
    if result[j]==1:
        continue
    else:
        ans+=combinations_count(result[j],2)

print(ans)

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

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

Solution (Python):
from collections import Counter

total = 0
n = int(input())
word_list = ["".join(sorted(input())) for _ in range(n)]
count_words = dict(Counter(word_list))
for item in count_words:
    ans = 0
    tmp = count_words[item] - 1
    ans = 1/2 * tmp * (tmp + 1)
    total += ans
print(int(total))

Solution (Python):

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

ans = 0
already_exist = {}

for i in range(N):
    if S[i] not in already_exist:
        already_exist[S[i]] = 0
    else:
        already_exist[S[i]] += 1
        ans += already_exist[S[i]]







print(ans)

Solution (Python):
n=int(input())
a=[]
ans=0
for i in range(n):
  s=list(input())
  s.sort()
  a.append(str(s))
a.sort()
y=''
w=0
c=[]
for x in a:
  if y==x:
    w+=1
  else:
    c.append(w)
    w=1
  y=x
c.append(w)
c=c[1:]
for x in c:
  ans+=x*(x-1)//2
print(ans)

Solution (Python):
from collections import Counter,defaultdict
N =int(input())
S = []

dict=defaultdict(int)
ans=0
for _ in range(N):
    s=''.join(sorted(input()))
    ans+=dict[s]
    dict[s]+=1
print(ans)

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

def cbn(n):
    if n == 1:
        return 0
    else:
        return n * (n - 1) // 2

N = int(input())
S = [sorted(input()) for _ in range(N)]
S.sort()
print(sum(cbn(len(list(l))) for s, l in groupby(S)))

Solution (Python):
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        
        Sum += hoge*(hoge-1)//2
        hoge = 1

print(Sum)

Solution (Python):
from collections import Counter
n=int(input())
l=["".join(sorted(list(str(input())))) for i in range(n)]
cnt=Counter(l)
ans=0
for i in set(l):
  n=cnt[i]
  ans+=n*(n-1)//2
print(ans)

Solution (Python):
import collections
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)]
split_s = [''.join(sorted([j for j in i])) for i in s]

c = collections.Counter(split_s)
ans = 0
for i in c.values():
    if i > 1:
        ans += cmb(i,2)

print(ans)

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

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


def num_cmb(a, b):
    enum = 1
    denom = 1
    for i in range(b):
        enum *= (a - i)
        denom *= (b - i)
    return enum // denom


sum = 0
count = 1
prev = s[0]
for s_i in s[1::]:
    if prev == s_i:
        count += 1
    else:
        sum += num_cmb(count, 2)
        count = 1
        prev = s_i
if 0 < count:
    sum += num_cmb(count, 2)
print(sum)

Solution (Python):
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter()
count = 0
for word in s:
  a = ''.join(sorted(word))
  count += c[a]
  c[a] += 1
print(count)

Solution (Python):
import math
n = int(input())
s_list = []
for _ in range(n):
    s_list.append(sorted(input()))
s_list = sorted(s_list)

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


eq_count = 0
count = 0
for i in range(1,n):
    if s_list[i-1] == s_list[i]:
        eq_count = eq_count + 1
    elif eq_count != 0:
        count = count + combinations_count(eq_count+1,2)
        eq_count = 0
    if i == n-1 and eq_count!=0:
        count = count + combinations_count(eq_count+1,2)

print(count)

Solution (Python):
from collections import Counter
n = int(input())
s = []
for i in range(n) :
  str = input()
  s.append(''.join(sorted(str)))
  
sd = Counter(s)

ans = 0
for v in sd.values():
    if v != 1 :
      ans += int(v*(v-1)*0.5)

print(ans)

Solution (Python):

from collections import Counter
N=int(input())
S=[input() for i in range(N)]

ctr=Counter()
ans=0

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

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

arr = []

for i in range(num):
    arr.append("".join(sorted(input())))


c = collections.Counter(arr)


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

print(cnt)

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

Solution (Python):
n=int(input())
l=sorted([''.join(sorted(input())) for _ in range(n)])
c=1
ans=[]
for i in range(n-1):
  if l[i] == l[i+1]:
    c += 1
  else:
    ans.append((c*(c-1))/2)
    c=1
ans.append((c*(c-1))/2)
print(int(sum(ans)))

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

for i in range(N):
    Si = S[i]
    Si.sort()
    Si2 = ''.join(Si)
    S[i] = Si2

ans = 0
Sc = collections.Counter(S).most_common()
for s in Sc:
    ans += s[1]*(s[1]-1)//2

print(ans)

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

print(ans)

Solution (Python):
from functools import reduce

N = int(input())

strings = []

for _ in range(N):
    s = input()
    strings.append(reduce(lambda a, b: a + b, sorted(s)))

strings = sorted(strings)

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

ans += counter * (counter - 1) / 2
        
print(int(ans))

Solution (Python):
import collections
n = int(input())
s = []
for i in range(n):
    s.append("".join(sorted(list(input()))))
c = collections.defaultdict(int)
ans = 0
for t_s in s:
    c[t_s] += 1
    ans += c[t_s] - 1
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
dic = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}

ans = []
for i in range(N):
    si = input()
    a = [0]*26
    s = ""
    for j in range(10):
        a[dic[si[j]]-1] += 1
    for k in range(26):
        s = s + "a"
        s = s + str(a[k])
    ans.append(s)
c = Counter(ans)
b = 0
for v in c.values():
    if v > 1:
        b += v*(v-1)//2
    else:
        pass
print(b)

Solution (Python):
import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
ans = [ans[1]*(ans[1]-1)//2 for ans in ans_list if not ans[1]==1]
ans_len = len(ans)
if ans_len==0:
    print(0)
else:
    print(sum(ans))

Solution (Python):
N = int(input())
lista = []
for n in range(N):
    sn = sorted(list(input()))
    
    lista.append(sn)
listaa = sorted(lista)    
ans = 0
count = 0
for a in range(1,N):
    if listaa[a] == listaa[a-1]:
        count += 1
        ans = ans + count
    else:
        count = 0
print(ans)

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

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result

ans = 0
n_same_str = 1
for i in range(N-1):
    if L[i] == L[i+1]:
        n_same_str += 1
    else:
        if n_same_str >= 2:
            ans += comb(n_same_str, 2)
        n_same_str = 1

if n_same_str >= 2:
            ans += comb(n_same_str, 2)

print(ans)

Solution (Python):
import math

N = int(input())
s = [list(input()) for i in range(N)]
S = []

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

for i in range(N):
  s[i].sort()
  string = ''.join(s[i])
  S.append(string)
  
a = {}
answer = 0
for i in range(N):
  if S[i] not in a.keys():
    a[S[i]] = 1
  else:
    a[S[i]] += 1
else:
  for j in a.values():
    if j != 1:
      answer += comb(j, 2)
  else:
    print(answer)

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

ans = 0
cnt = 0
tmp = ss.pop(0)
for s in ss:
    if tmp == s:
        cnt+=1
    elif cnt > 0:
        tmp = s
        ans+=((cnt+1) * cnt // 2)
        cnt = 0
    else:
        tmp = s
        cnt = 0
print(ans + ((cnt+1) * cnt // 2))

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

s_list = sorted(s_list)

count = 0
total = 0
s_prev = s_list[0]
for s in s_list[1:]:
    if s_prev == s:
        count += 1
    else:
        if count > 0:
            total += count * (count + 1) // 2
            count = 0
    s_prev = s

if count > 0:
    total += count * (count + 1) // 2

print(total)

Solution (Python):
from collections import Counter,defaultdict
import sys
input = sys.stdin.readline

N = int(input())
s = [None] + [list(input()) for _ in range(N)]

count = defaultdict(int)

answer = 0
for i in range(1,N+1):
    c = Counter(s[i])
    c = sorted(c.items(), key=lambda x:x[0])
    
    str_c = ""
    for key,item in c:
        str_c += key*item
    answer += count[str_c]
    count[str_c] += 1

print(answer)

Solution (Python):
N = int(input())
m = dict()
ans = 0
for _ in range(N):
    s = input()
    s = ''.join(sorted(s))
    if s in m:
        ans += m[s]
        m[s] += 1
    else:
        m[s] = 1
print(ans)

Solution (Python):



from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

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

ret = 0
for v in H.values():
    if v >= 2:
        ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

Solution (Python):
n = int(input())
a = [''.join(sorted(input())) for i in range(n)]
ans = 0
count = 0
a.sort()
for i in range(1,n) :
    if a[i] == a[i-1] :
        count += 1
        ans += count
    else :
        count = 0
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())
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):
import sys
import numpy as np
from collections import Counter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]


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()
S = [[s for s in input().strip()] for _ in range(N)]

words = []
for s in S:
	s.sort()
	words.append(s)

words.sort()

ans = []
tmp = ''
num = -1
for w in words:
	
	if tmp == w:
		
		ans[num] += 1
		
	else:
		
		tmp = w
		num+=1
		ans.append(1)
		
		


count = 0
for a in ans:
	if a != 1: count += cmb(a, 2)

print(count)

Solution (Python):




import numpy as np

N = int(input())
S = []
hash_table = {}

a_ascii = ord('a')
bins_of_char = np.zeros((N, 26),dtype=np.int)
num_of_anagram = 0

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

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


print(num_of_anagram)

Solution (Python):
import collections
N = int(input())
array = []
for i in range(N):
    s = input()
    dict = {}
    for j in range(len(s)):
        if s[j] not in dict:
            dict[s[j]] = 1
        else:
            dict[s[j]] += 1
    dict = sorted(dict.items())

    array.append(str(dict))
sum = 0
c = collections.Counter(array)
for v in c.values():
    sum += int(v*(v-1)/2)
print(sum)

Solution (Python):
from collections import Counter

kw = Counter()

n = int(input())

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

sum = 0
for _, val in kw.most_common():
    sum += val * (val - 1) // 2

print(sum)

Solution (Python):
from collections import Counter

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

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

        di[s] += 1
    
    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

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

        di[s] += 1
    
    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
s = [''.join(sorted(input())) for i in range(n)]
s.sort()
s.append("a")
b=1
c=0
for i in range(n):
    if s[i]!=s[i+1]:
        c+=(b*(b-1))//2
        b=1
    else:
        b+=1
print(c)

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

s.insert(len(s), "")

current = 0
ans = 0
for i in range(len(s)):
    if s[current] != s[i]:
        num = i - current
        if num >= 2:
            ans += math.factorial(num)//(math.factorial(2)*math.factorial(num-2))

        current = i

print(ans)

Solution (Python):
from math import factorial
n = int(input())
ans_list = []
num_list = []
for i in range(n):
    s = list(input())
    s.sort()
    ans_list.append("".join(s))
ans_list.sort()
count = 1
for i in range(n-1):
    if ans_list[i] == ans_list[i+1]:
        count += 1
    else:
        num_list.append(count)
        count = 1
num_list.append(count)
ans = 0
for i in range(len(num_list)):
    if num_list[i] != 1:
        ans += factorial(num_list[i]) // factorial(2) // factorial(num_list[i]-2)
print(ans)

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

List=[''.join(sorted(input())) for i in range(N)]
List.sort()
List.extend("1")
cnt = 0
num = 0

for i in range(N):
  a = List[i]
  b = List[i+1]
  if a != b:   
    cnt = cnt + num * (num+1) / 2
    num = 0 
  else:
    num = num + 1

print(int(cnt))

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

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

a={}
ans=0
for i in range(n):
    s=input()
    b=sorted(s)
    w=''.join(b)
    if not a.get(w):
        a[w]=1
    else:
        v=a[w]
        v +=1
        a[w]=v

for v in a.values():
    if v > 1:
        c=int((v*(v-1))/2)
        ans +=c
    
print(ans)

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