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())
S=[]
count=0
ans=0
for i in range(N):
    s=sorted(input())
    S.append(s)
S.sort()
x=S[0]
for i in range(1,N):
    if(S[i]==x):
        count += 1
    else:
        ans=ans+(count+1)*count//2
        count=0
        x=S[i]
ans=ans+(count+1)*count//2
print(ans)

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

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

Solution (Python):
def kaijou(n):
  sum = 0
  for i in range(n):
    sum += i
  return sum

num = int(input())

alplist = []

for i in range(num):
  alplist.append(sorted(input()))
alplist.sort()
tmp = []
count = 1
sum = 0
for _alplist in alplist:
  if tmp == _alplist:
    count += 1
  else:
    sum += kaijou(count)
    count = 1
    tmp = _alplist
sum += kaijou(count)
print(sum)

Solution (Python):
import math

n = int(input())
S = [list(input()) for i in range(n)]
ans = 0
for s in S:
  s.sort()
  "".join(s)
S.sort()
S.append(0)
cnt = 0
for i in range(n):
  if S[i]==S[i+1] :
    cnt += 1
  else:
    cnt += 1
    ans += math.factorial(cnt)/(math.factorial(cnt-2)*2) if cnt >= 2 else 0
    cnt = 0
print(int(ans))

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

prev = ''
count = 0
res = 0

for s in S:
    if s == prev:
        count += 1
        res += count
    else:
        count = 0
    prev = s

print(res)

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

prev = ''
count = 0
res = 0

for s in S:
    if s == prev:
        count += 1
        res += count
    else:
        count = 0
    prev = s

print(res)

Solution (Python):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
s = [str(input()) for _ in range(n)]
s = sorted(["".join(sorted(_)) for _ in [i for i in s]])
ans = 0
preb = str()
cnt = 1
for line in s:
  if preb == line:
    cnt += 1
  elif cnt >= 2:
    ans += cmb(cnt, 2)
    cnt = 1
  else:
    cnt = 1
  preb = line
if cnt >= 2:
    ans += cmb(cnt, 2)
print(ans)

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

Solution (Python):
from sys import exit, stderr, stdin
input = stdin.readline

from collections import defaultdict


def main():
    N = int(input())
    A = [0]*N
    dic = defaultdict(int)
    for i in range(N):
        A[i] = "".join(sorted((input()[:-1])))
        dic[A[i]] +=1
    ans = 0
    for k in dic:
        if dic[k] >= 2:
            ans += dic[k]*(dic[k]-1)//2
    print(ans)






if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
ana = {}
answer = 0

for i in range(N):
    s = sorted(input())
    new_str = ''.join(s)
    flag = 0

    if new_str in ana.keys():
        ana[new_str] += 1
        answer += ana[new_str]
        flag = 1

    if flag == 0:
        ana[new_str] = 0

print(answer)

Solution (Python):
n = int(input())
N = []
for i in range(n):
    N.append(input())
Nn = [sorted(j) for j in N]
Nn.sort()
Nh = []
for let in Nn:
    Nh.append(('').join(let))
c_dict = {}
for letters in Nh:
    if letters not in c_dict:
        c_dict[letters] = 1
    elif letters in c_dict:
        c_dict[letters] += 1
ans_list = []
for letter, num in c_dict.items():
    ans_list.append((num * (num-1))//2)
print(sum(ans_list))

Solution (Python):
def main():
  n = int(input())
  l = []
  d = {}
  res = 0
  for i in range(n):
    s = input()
    l.append(''.join(sorted(s)))
  for j in range(n):
    if d.get(l[j]) is None:
      d[l[j]] = 1
    elif d.get(l[j]) > 0:
      d[l[j]] += 1
      res += d[l[j]] - 1
    else:
      print('error!')
      quit()
  
  return res
  
if __name__ == "__main__":
  res = main()
  print(res)

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

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

for i in range(N):
  s[i] = list(s[i])
  s[i].sort()
  s[i] = "".join(s[i])
  
x = Counter(s).most_common()
cnt = 0
for i in range(len(x)):
  if x[i][1] >1:
    cnt += factorial(x[i][1]) // 2 // factorial(x[i][1] -2)
print(cnt)

Solution (Python):
N = int(input())
S = [str(''.join(sorted(input()))) for _ in range(N)]

cnt = {}

for s in S:
    if s in cnt.keys():
        cnt[s] += 1
    else:
        cnt[s] = 1

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

Solution (Python):
N = int(input())
s = sorted([list(sorted(input())) for _ in range(N)]) + [" "]
ans = 0
cnt = 1
for i in range(N):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1

print(ans)

Solution (Python):
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))

from collections import defaultdict
n = I1()
d = defaultdict(int)
for i in range(n):
    d["".join(sorted(input()))]+=1
res=0
for i in d.keys():
    if d[i] > 1:
        yy=d[i]-1
        res+=yy*(yy+1)//2
print(res)

Solution (Python):
n = int(input())
num_of_anagram = dict()
ans = 0

for _ in range(n):
    s = input()
    s = ''.join(sorted(list(s)))
    if s in num_of_anagram:
        num_of_anagram[s] += 1
        ans += num_of_anagram[s]
    else:
        num_of_anagram[s] = 0

print(ans)

Solution (Python):
n = int(input())
lis = []
for _ in range(n):
  s = list(str(input()))
  s.sort()
  lis.append(s)
lis.sort()
ans = 0
num = 0
for i in range(n-1):
  if lis[i+1] == lis[i]:
    num += 1
  else:
    ans += (num * (num+1))//2
    num = 0
ans += (num * (num+1))//2
print(ans)

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


if __name__ == "__main__":
    n = int(input())
    s_array = [''.join(sorted(input()[:-1])) for _ in range(n)]

    s_array.sort()
    ans = 0
    count = 0
    word = s_array[0]
    for i in range(1, n):
        if(word == s_array[i]):
            count += 1
        else:
            ans += (count*(count+1))//2
            count = 0
        word = s_array[i]

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

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]
for i in range(N):
  s[i] = "".join(sorted(s[i]))
t = {}
for i in range(N):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k]*(t[k]-1)//2 for k in t))

Solution (Python):
import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))


s = sorted(s)
tango = "yeeeh"
x = 0

for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

print(ans)

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

n = int(input())
s = [''.join(sorted(input())).strip() for _ in range(n)]
c = Counter(s)
ans=sum(map(lambda x: x*(x-1)//2, c.values()))
print(ans)

Solution (Python):
N = int(input())
strings = sorted([sorted(input()) for _ in range(N)])
ans = 0
temp = 1
for s1, s2 in zip(strings, strings[1:]):
    if s1 == s2: temp += 1
    else:
        ans += temp * (temp - 1) // 2
        temp = 1
ans += temp * (temp - 1) // 2
print(ans)

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

dic={}

for i in  s:
    i = sorted(i)
    i = ''.join(i)
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

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

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

ans = 0
word= {}

for j in s_list:

    a = ''.join(sorted(j))
    if a in word:
        ans += word[a]
        word[a] += 1
    else:
        word[a] = 1
    
print(ans)

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

Solution (Python):
from collections import Counter
n = int(input())
s = Counter(''.join(sorted(input())) for i in range(n))
print(sum(map(lambda x : x * (x-1) // 2, s.values())))

Solution (Python):
from collections import Counter
n = int(input())
s = Counter("".join(sorted(input())) for i in range(n))
print(sum(map(lambda x : x * (x-1) // 2, s.values())))

Solution (Python):
from collections import Counter

n = int(input())
s =  Counter("".join(sorted(input())) for i in range(n))

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

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

li1 = []
for _ in range(n):
    s = list(input())
    li1.append(sorted(s))

cnt = 0
li2 = sorted(li1)
li3 = []
for i in range(1, len(li2)):
    if li2[i] == li2[i-1]:
        cnt += 1
    else:
        li3.append(cnt)
        cnt = 0
    if i == len(li2)-1:
        li3.append(cnt)

cnt1 = 0
for i in li3:
    cnt1 += (i*(i+1))//2
    
print(cnt1)

Solution (Python):
from collections import Counter

n = int(input())
s =  Counter("".join(sorted(input())) for i in range(n))

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

i  = lambda: int(input())
s  = lambda: input()

str_m = {}
for _ in range(i()):
  S = ''.join(sorted(s()))
  if S in str_m:
    str_m[S] += 1
  else:
    str_m[S] = 1

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

print(count)

Solution (Python):
import collections
import math

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

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)


c = collections.Counter(str_L)

str_L = list(set(str_L))


ans = 0
r = 2

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

for val in str_L:
    n = c[val]
    
    ans = ans + combinations_count(n,r) 

print(ans)

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 v in d.values():
  if v>=2:
    ans += v*(v-1)//2
print(ans)

Solution (Python):


import collections 
 
N=int(input())
l=[]
 
for i in range(N):
    l.append(list(input()))
    l[i].sort()
    l[i]="".join(l[i])
    
clist=list(collections.Counter(l).values())

count=0
for c in clist:
    count+=int(c*(c-1)//2)
    
print(count)

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

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

ans = sorted(ans)

voc = "a"
A = 0
c = 0
for i in range(N):
    if voc == ans[i]:
        c += 1
    else:
        A += c * (c + 1) // 2
        c = 0
    voc = ans[i]

A += c * (c + 1) // 2

print(A)

Solution (Python):
import collections
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
c = collections.Counter(S).values()
cand = list(c)
cand = [i for i in cand if i > 1]
for i in range(len(cand)):
    cand[i] = cand[i]*(cand[i]-1)//2
print(sum(cand))

Solution (Python):
import collections

N = int(input())

A = []

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

C = list(collections.Counter(A).values())

s = 0

for c in C:
  s += int(((c-1)*c)//2)
  
print(s)

Solution (Python):

N = int(input())
anagram_dict = {}
ans = 0

for i in range(N):
    s= ''.join(sorted(list(input())))
    if s in anagram_dict:
        ans += anagram_dict[s]
        anagram_dict[s] += 1
    else:
        anagram_dict[s]=1

print(ans)

Solution (Python):
def comb(n):
    return n * (n - 1) // 2

N=int(input())
S=[]
for i in range(N):
    S.append(input())

w_list = []

for ss in S:
    s = sorted([i for i in ss])
    w_list.append("".join(s))
    
w_list.sort()

ans = 0
anagram = 1
temp = w_list[0]

for i in range(1, N):
    if temp == w_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = w_list[i]

ans += comb(anagram)
    
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
d,ans = defaultdict(int),0
for i in range(n):
    s = tuple(sorted(list(input())))
    d[s]+=1
for i in d.values(): ans+=i*(i-1)//2
print(ans)

Solution (Python):
n = int(input())
counter = 0
tmp = {}
for _ in range(n):
    s = str(sorted(input()))
    if s in tmp:
        counter += tmp[s]
        tmp[s] += 1
    else:
        tmp[s] = 1
print(counter)

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

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

print(ans)

Solution (Python):
d={}
s=0
for _ in range(int(input())):
  l=input()
  l=str(sorted(l))
  f=d.keys()
  if l not in f:
    d[l]=0
  else:
    d[l]+=1
    s+=d[l]
print(s)

Solution (Python):
d={}
s=0
for i in range(int(input())):
    j=str(sorted(input()))
    if j in d:
        d[j]+=1
        s+=d[j]
    else:
        d[j]=0
print(s)

Solution (Python):
d={}
c=0
for i in open(0):i=str(sorted(i));t=d.get(i,0);c+=t;d[i]=t+1
print(c)

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

sample = {}
sam = 0

for i in range(n):
    s = sorted(input())
    s = ''.join(s)
    if s in sample:
        sample[s] += 1
        sam += sample[s] -1
    else:
        sample[s] = 1
print(sam)

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

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

Solution (Python):
n = int(input())
c = 0
c_dict = {}
l = []
for i in range(n):
    s_listed = sorted(list(input()))
    s = ''.join(s_listed)
    if s in c_dict.keys():
        c_dict[s] += 1
        c += c_dict[s] - 1
    else:
        c_dict[s] = 1
print(int(c))

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

N = int(input())
dic = {}
count = 0
for _ in range(N):
    x = "".join(sorted(input()))
    if x in dic:
        count += dic[x]
        dic[x] += 1
    else:
        dic[x] = 1

print(count)

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

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

ans = 0
dic ={} 

for s in  S:
   if s in dic:
      ans+=dic[s]
      dic[s]+=1
   else:
      dic[s] = 1


print(ans)

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

N = int(input())
hash = {}
count = 0
for _ in range(N):
    x = "".join(sorted(input()))
    if x in hash:
        count += hash[x]
    else:
        hash[x] = 0
    hash[x] += 1

print(count)

Solution (Python):
from math import factorial

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

N = int(input())
S = [input() for _ in range(N)]
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))

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


if __name__ == "__main__":
    main()

Solution (Python):
def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
print(anagram(N,S))

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

for i in range(0, N):
    si = input()
    si_sorted = "".join(sorted(list(si)))
    if si_sorted in d:
        d[si_sorted] = d[si_sorted] + 1
    else:
        d[si_sorted] = 1

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

print(res)

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

print(ans)

Solution (Python):
from collections import Counter

n = int(input())

s = set()
res = Counter([tuple(sorted(input())) for _ in range(n)])
print(sum((x*(x-1))//2 for x in res.values()))

Solution (Python):
n = int(input())
dict = {}
ans = 0
for _ in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    if tmp in dict:
        dict[tmp] += 1
        ans += dict[tmp]
    else:
        dict[tmp] = 0
print(ans)

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

print(ans)

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

Solution (Python):
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        result += tempres
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break
    result += tempres

print(result)

Solution (Python):
N = int(input())
letter_list = []
letter_dic = {}
ans = 0
for _ in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    if tmp in letter_dic:
        letter_dic[tmp] += 1
        ans += letter_dic[tmp]
    else:
        letter_dic[tmp] = 0

print(ans)

Solution (Python):
n = int(input())
buf = []
ans = 0

for i in range(n):
  lists = list(input())
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)

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

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

for i in range(N):
    k = ''.join(sorted(list(input())))
    if k in dic:
        cnt += dic[k]
        dic[k] += 1
    else:
        dic[k] = 1

print(cnt)

Solution (Python):
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = sum(x*(x-1)//2 for x in c.values())
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
c = Counter(S)
print(sum([k*(k-1)//2 for k in c.values()]))

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dict = defaultdict(int)
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        dict[str] += 1

    ans = 0
    for val in list(dict.values()):
        if 1 < val:
            ans += val*(val-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dp = {}
    ans = 0
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        if str in dp:
            ans += dp[str]
            dp[str] += 1
        else:
            dp[str] = 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  

from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for n in range(N):
  s = list(input())
  s.sort()
  k = tuple(s)
  dic[k] += 1
ans = 0
for k in dic.keys():
  if dic[k]<2:
    continue
  ans += cmb(dic[k],2)
print(ans)

Solution (Python):
from itertools import groupby
from math import factorial


N = int(input())
words = [input() for _ in range(N)]
groups = groupby(sorted([''.join(sorted(list(word))) for word in words]))

res = 0
for k, vs in groups:
    l = len(list(vs))
    if l >= 2:
        res += factorial(l) // (factorial(l - 2) * 2)

print(res)

Solution (Python):
A ={}
c = 0
for i in range(int(input())):
    a = str(sorted(input()))
    if a in A:
        A[a] += 1
        c += A[a]
    else:
        A[a] = 0
print(c)

Solution (Python):
import math
import sys


sys.setrecursionlimit(10**7)

N = int(input())
words = [input() for _ in range(N)]
patterns = sorted([''.join(sorted(list(word))) for word in words])

def count_list_duplicates(arr):
    dup, prev, c = [], '', 0
    for l in arr:
        if prev == l:
            c += 1
        else:
            dup.append(c)
            c = 1
        prev = l
    else:
        dup.append(c)

    return dup

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

res = 0
for d in count_list_duplicates(patterns):
    if d >= 2:
        res += combinations_count(d, 2)
        
print(res)

Solution (Python):

import collections

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [range(i) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(a))

Solution (Python):
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
st = []
ans = 0
for i in range(n):
    st.append(list(tuple(s[i])))
    st[i].sort()
    st[i] = str(st[i])
st.sort()
count = Counter(st)
for v in count.values():
    if v != 1:
        for n in range(1, v):
            ans += n
print(ans)

Solution (Python):
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = sorted(["".join(sorted(stdin.readline().rstrip())) for _ in range(n)])

gr = groupby(sary)

res = 0

for k, g in gr:
    num = len(list(g))
    if  num >= 2:
        res += num * (num - 1) // 2

print(res)

Solution (Python):
n = int(input())
s = dict()
count = 0
for i in range(n):
    t = "".join(sorted(list(input())))

    if not t in s.keys():
        s[t] = 1
    else:
        s[t] += 1
        count += s[t] - 1

print(count)

Solution (Python):
n = int(input())
s = list()
for i in range(n):
    s.append(list(input()))

t = dict()
l = 0

for i in range(len(s)):
    s[i].sort()
    k = "".join(s[i])
    if not k in t.keys():
        t[k] = 1
    else:
        t[k] += 1
        l += t[k] - 1

print(l)

Solution (Python):
def slove():
    import sys, collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for i, v in s:
        for j in range(1, v):
            t += j
    print(t)


if __name__ == '__main__':
    slove()

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
d = {}
c = 0

for i in s:
  tmp = "".join(sorted(i))
  if tmp not in d:
    d[tmp] = 0
  else:
    d[tmp] += 1
  c += d[tmp]
  
print(c)

Solution (Python):
import collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.values():
  if v != 1:
    for n in range(1,v):
      ctr+=n
      
print(ctr)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    count = 0
    d = {}
    for _ in range(N):
        s = ''.join(sorted(input()))
        try:
            d[s]
        except KeyError:
            d[s] = 0
        d[s] += 1
        if d[s] > 1:
            count += d[s] - 1
    print(count)

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

ans, d = 0, {}
for i in range(n):
    if s[i] in d.keys():
        ans += d[s[i]]
        d[s[i]] = d[s[i]] + 1
    else:
        d[s[i]] = 1
print(ans)

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

cnt = {}
ans = 0

for Si in S:
    x = "".join(sorted(list(Si)))
    if x not in cnt:
        cnt[x] = 0
    ans += cnt[x]
    cnt[x] += 1

print(ans)

Solution (Python):
from collections import Counter

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

ctr = Counter()
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x in ctr:
        ans += ctr[x]
    ctr[x] += 1

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):
from collections import defaultdict

n = int(input())

s = defaultdict(str)

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

print(ans)

Solution (Python):

n = int(input())
can = []
for _ in range(n):
  raw = input()
  made = []
  for k in range(10):
    made.append(ord(raw[k])-97)
  made.sort()
  can.append(made)
can.sort()
ans = 0
combo = 0
for i in range(1,n):
  if can[i-1] == can[i]:
    combo += 1
  else:
    combo = 0
  ans += combo
print(ans)

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

from collections import Counter
c = Counter(s_arr)
cnt = 0
for i in c:
    cnt += c[i]*(c[i]-1)//2
print(cnt)

Solution (Python):
A ={}
c = 0
for i in range(int(input())):
    a = str(sorted(input()))
    if a in A:
        A[a] += 1
        c += A[a]
    else:
        A[a] = 0
print(c)

Solution (Python):
import math
N = int(input())
L = [input() for i in range(N)]
L = sorted(list(map("".join, list(map(sorted, list(map(list, L)))))))
c = 0
ans = 0
for j in range(1,N):
    if not L[j] == L[j - 1]:
        ans += (j - c)*(j - c - 1)/2
        c = j
    elif j + 1 == N:
        ans += (j + 1 - c)*(j - c)/2
print(int(ans))

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

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

word_dict = dict()

counter = 0

for i in range(n):
  word_dict.setdefault(string_list[i], 0)
  word_dict[string_list[i]] += 1
  if word_dict[string_list[i]] != 1:
    counter += word_dict[string_list[i]] - 1
  
print(counter)

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

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

print(int(ans))

Solution (Python):
from collections import Counter

n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
c = Counter(s)
ans = sum(sum(range(i)) for i in c.values())
print(ans)

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dp = {}
    ans = 0
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        if str in dp:
            ans += dp[str]
            dp[str] += 1
        else:
            dp[str] = 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n_str = int(input().strip())

str_dict = {}

for i in range(n_str):
    string = input().strip()
    sorted_str = ''.join(sorted(string))
    if sorted_str in str_dict:
        str_dict[sorted_str] += 1
    else:
        str_dict[sorted_str] = 1

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

print(num_pairs)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for i, v in s:
        for j in range(v-1, 0, -1):
            t += j
    print(t)


if __name__ == '__main__':
    slove()

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

cnt = 0
for i in s:
    for j in range(1, i[1]):
        cnt += j
print(cnt)

Solution (Python):

n = int(input())
s = [0]*n
count = 0
each_count = {}

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)

Solution (Python):

n = int(input())
s = [0]*n
count = 0
each_count = {}

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)

Solution (Python):
n = int(input())
ans = {}
for i in range(n):
    s = input()
    t = []
    for i in range(len(s)):
        t.append(s[i])
    t.sort()
    k = "".join(t)
    if k in ans:
        ans[k] = ans[k]+1
    else:
        ans[k] = 0
answer = 0
for i in ans:
    j = ans[i]
    answer += j*(j+1)//2
print(answer)