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

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

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

res = 0
for i in range(N):
    s = "".join(sorted(sys.stdin.readline().strip()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

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

print(res)

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

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

Solution (Python):
from collections import Counter, deque, OrderedDict












import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n = int(input())
    d = [''.join(sorted(list(input()))) for _ in range(n)]
    dd=Counter(d)
    cnt=0
    for i in dd.values():
        cnt += i*(i-1)//2
    print(cnt)




resolve()

Solution (Python):
from sys import stdin
def nC2(n):
    return n*(n-1)//2

def main():
    
    readline=stdin.readline
    N=int(readline())
    s=[""]*N
    for i in range(N):
        a=list(readline().strip())
        a.sort()
        s[i]="".join(a)

    d=dict()
    for i in range(N):
        if s[i] not in d:
            d[s[i]]=1
        else:
            d[s[i]]+=1

    res=0
    for v in d.values():
        if v==1:
            pass
        else:
            res+=nC2(v)

    print(res)
    
if __name__=="__main__":
    main()

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

n = int(input())

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    s = list(input().rstrip())
    s.sort()
    d["".join(s)] += 1

ans = 0

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

print(ans)

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    S=[input().rstrip() for _ in range(N)]
    from collections import Counter,defaultdict
    from string import ascii_lowercase
    d=defaultdict(int)
    for s in S:
        C=Counter(s)
        t=0
        for i,a in enumerate(ascii_lowercase):
            t+=C[a]*(11**i)
        d[t]+=1
    ans=0
    for v in d.values():
        ans+=v*(v-1)//2
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=["".join(sorted(list(input().rstrip()))) for i in range(n)]
c=Counter(lis)

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

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

L = []
for i in range(N):
    x = list(input())
    x.sort()
    x = "".join(x)
    L.append(x)
    
from collections import Counter
L = Counter(L)
import math

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

ans = 0
for i in L:
    a = L[i]
    if a > 1:
        ans += combinations_count(a,2)
print(ans)

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

dic = {}
for i in range(n):
    s = input()
    lst = [0 for j in range(30)]
    for j in range(10):
        lst[ord(s[j])-ord('a')] += 1
    string = ''.join(map(str, lst))
    if string in dic:
        dic[string] += 1
    else:
        dic[string] = 1

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

N = int(input())

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

for i in range(N):
    S[i].sort()

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

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

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    ana = defaultdict(int)
    n = int(input())
    for i in range(n):
        s = "".join(sorted(input()))

        ana[s] += 1
    ans = 0
    for k,v in ana.items():
        ans += v*(v-1)//2
    print(ans)
if __name__ == '__main__':
  main()

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

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

    appearance = dict()
    for i in range(n):
        s[i] = tuple(sorted(s[i]))
        if s[i] not in appearance:
            appearance.update({s[i]: 1})
        else:
            appearance[s[i]] += 1

    ans = 0
    for _, x in appearance.items():
        ans += (x * (x - 1)) // 2

    print(ans)

if __name__ == '__main__':
    main()

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

D={}

for i in range(N):
    s=input()
    s="".join(sorted(s))
    if s not 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):
n = int(input())
D = {}
ans = 0
for i in range(n):
    s = str(input())
    d = [0]*26
    for j in range(len(s)):
        c = ord(s[j])-ord('a')
        d[c] += 1
    d = tuple(d)
    if d in D:
        ans += D[d]
        D[d] += 1
    else:
        D[d] = 1
print(ans)

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

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

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

print(ans)

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

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

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

Solution (Python):
import numpy as np
from collections import defaultdict

memo = defaultdict(int)

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

ans = np.array(list(memo.values()))
tmp = ans - 1
ans = (ans*tmp)/2

print(int(ans.sum()))

Solution (Python):
import numpy as np
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

ans = defaultdict(int)

for s in S:
    key = "".join(sorted(s))
    ans[key] += 1

sum = 0

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

print(sum)

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

Solution (Python):
N=int(input())
s=["".join(sorted(input())) for i in range(N)]
s.sort()
ans=0
t=0
for i in range(N):
  if s[t]!=s[i]:
    ans+=(i-t)*(i-t-1)//2
    t=i
i+=1
ans+=(i-t)*(i-t-1)//2

print(ans)

Solution (Python):
N = int(input())
cnt = dict()
output = 0

for i in range(N):
    string = ''.join(sorted(input()))
    cnt.setdefault(string, 0)
    output += cnt[string]
    cnt[string] += 1

print(output)

Solution (Python):
def myAnswer(N:int,S:list) -> int:
   counter = 0
   dic = {}
   for s in S:
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s] = 0
   for value in dic.values():
      counter += (value * (value + 1)) // 2
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = ["".join(sorted(list(input()))) for _ in range(N)]
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

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

from collections import Counter

ans=[]
d={}
cnt=0
for i in range(N):
    s=list(input())
    s=sorted(s)
    
    s= ''.join(s)

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

total=0

for _,value in d.items():
    if value==1:
        continue
    else:
        total +=value*(value-1)/2

print(int(total))

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

C = []
for s in S:
    T = tuple(sorted(s))
    C.append(T)

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

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

Solution (Python):
from bisect import bisect_left, bisect_right

N = int(input())
dic = []
ans = 0

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

dic.sort()

for i in range(N):
  S = dic[i]
  r = bisect_right(dic, S)
  ans += r-i-1


print(ans)

Solution (Python):

def solve():
    n = int(input())
    a = 0
    s = {}
    for i in range(n):
        t = ''.join(sorted(input()))
        b = s.get(t, 0)
        a += b  
        s[t] = b+1
    print(a)


solve()

Solution (Python):
N=int(input())
dic={}
for i in range(N):
  s=sorted(list(input()))
  s="".join(s)
  if s in dic:
    dic[s]+=1
  else:
    dic[s]=1
count=0
u=len(dic)
for i in range(u):
  kk=dic.popitem()
  count+=kk[1]*(kk[1]-1)/2
print(int(count))

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
s.sort()
ans = 0
t = 0
for i in range(1,n):
    if s[i-1]==s[i]:
        t += 1
        if i==n-1:
            ans += t*(t+1)/2
    else:
        if t>0:
            ans += t*(t+1)/2
            t = 0

print(int(ans))

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

Solution (Python):
from functools import reduce

N = int(input())
Sn = [''.join(sorted(list(input()))) for _ in range(N)]
dic = {}
for k in range(len(Sn)):
  if Sn[k] in dic:
    dic[Sn[k]] += 1
  else:
    dic[Sn[k]] = 1

ans = list(map(lambda x:x*(x-1)//2, list(dic.values())))
ans = sum(ans)
print(ans)

Solution (Python):
n=int(input())
count=0
dic={}
ppp=""
for i in range(n):
  s=list(input())
  s.sort()
  s=ppp.join(s)
  if s in dic:
    dic[s]+=1
  else:
    dic[s]=1
kouho=0
for j in range(len(dic)):
  kk=dic.popitem()
  c=kk[1]
  kouho+=(c*(c-1))//2
print(kouho)

Solution (Python):
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math


sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())




s = {}
ans = 0

for i in range(n):
    l = list(str(stdin.readline().rstrip()))
    l.sort()
    l = str(l)
    if l in s:
        s[l] += 1
        ans += s[l] -1
    else:
        s[l] = 1

print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

from collections import defaultdict as dl
n  =ii()
s = []
for _ in range(n):
    ss = input()
    a = sorted(ss)
    a = "".join(a)
    s.append(a)
dic = dl(int)
for i in range(n):
    dic[s[i]] += 1

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

Solution (Python):
import collections

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

Solution (Python):
import collections

n = int(input())
def sort_string(st):
  res = list(st)
  res.sort()
  return "".join(res)

s = [sort_string(input()) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for n in c.values():
  ans += n*(n-1)//2
print(ans)

Solution (Python):
from collections import Counter
import math
n = int(input())
s_list = ["".join(map(str,sorted(input()))) for i in range(n)]
s_counter = Counter(s_list)
s_len = len(s_counter)
s_most = s_counter.most_common()

ans = 0
for i in range(s_len):
    if s_most[i][1] != 1:
        dum = s_most[i][1]
        ans += (dum * (dum-1)) // 2
    else:
        break
print(ans)

Solution (Python):
import itertools
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N=int(input())
S=[input() for i in range(N)]
d={}

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

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

Solution (Python):
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

Solution (Python):
N=int(input())
S={}
c={}
for i in range(N):
    s=''.join(sorted(input()))  
    if s in S:
        c[s]+=1
        if c[s]>=2:
            S[s]=S[s]+c[s]
        else:
            S[s]+=1

    else:
        S[s]=0
        c[s]=0
print(sum(S.values()))

Solution (Python):
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

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

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    s = ["".join(sorted(input())) for _ in range(N)]
    S = Counter(s)
    ans = 0
    for a in S.values():
        ans += sigma(a)
    print(ans)


def sigma(x):
    sum = 0
    for i in range(1, x):
        sum += i
    return sum


if __name__ == "__main__":
    main()

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

result=[]

for item in range(n):
  s=list(input())
  
  s.sort()
  result.append("".join(s))

tmp_cnt=0
count=0
temp=""
result.sort()
result.append("")


for item in result:
    if temp!=item:
        count+=tmp_cnt*(tmp_cnt-1)//2
        tmp_cnt=1
        temp=item
    else:
        tmp_cnt+=1

print(count)

Solution (Python):
from collections import defaultdict


def main():
    N = int(input())
    counter = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(input()))
        counter[s] += 1
    answer = 0
    for c in counter.values():
        answer += c * (c - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
s_dict = {}
ans = 0
for _s in s:
  _s = sorted(_s)
  _s = ''.join(_s)
  s_dict.setdefault(_s, 0)
  ans += s_dict[_s]
  s_dict[_s] += 1
print(ans)

Solution (Python):
from collections import defaultdict
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    if n <= 1:
        return 0
    return P(n, r)//math.factorial(r)
N = int(input())
d = defaultdict(int)
for i in range(N):
    d[','.join(sorted(input()))] += 1
ans = 0
for value in d.values():
    ans += C(value,2)
print(ans)

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

c=Counter(s)

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

print(ans)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [tuple(sorted(iss())) for _ in range(N)]
    S = collections.Counter(T)
    print(sum(v*(v-1)//2 for v in S.values()))


if __name__ == '__main__':
    main()

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

Solution (Python):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Solution (Python):

n=int(input())
st=dict()
for i in range(n):
    si=list(input())
    si.sort()
    si="".join(si)
    if si in st:
        st[si]+=1
    else:
        st[si]=1
        
icnt=0
for i in st.values():
    if i>1:
        icnt+=i*(i-1)//2
        
print(icnt)

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

l = [""] * n
for i in range(n):
    temp = input()
    l[i] = "".join(sorted(temp))

c = dict(collections.Counter(l))

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

print(ans)

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

a = [input() for i in range(n)]

for i in range(n):
    a[i] = ''.join(sorted(a[i]))

a = sorted(a)

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

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

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

cnt = 0
anagrams = {}
for _ in range(n):
    s = input()
    sorted_s = ''.join(sorted(s))
    if sorted_s in anagrams:
        anagrams[sorted_s] += 1
        cnt += anagrams[sorted_s]
    else:
        anagrams[sorted_s] = 0

print(cnt)

Solution (Python):
from collections import Counter

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

Solution (Python):
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
s = sorted(S)
s.append(["X"])
sum = 0
num = 1
for i in range(N):
  if s[i] == s[i+1]:
    num += 1
  else:
    sum += num*(num-1)//2
    num = 1
print(sum)

Solution (Python):
import collections
from math import factorial

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

n = int(input())
li = []
ans = 0

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

c = list(collections.Counter(li).values())
c.sort(reverse=True)

for i in c:
    if i == 1:
        break
    ans += combinations_count(i, 2)

print(ans)

Solution (Python):
import itertools
import math
from scipy.misc import comb
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += comb(num, 2,exact=True)
print(math.floor(sum))

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

dic = {}


def twoKimuawaseSum(num):
    result = 0
    for i in range(1, num):
        result += i
    return result


for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += twoKimuawaseSum(num)
print(math.floor(sum))

Solution (Python):

import math



def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    N = int(input())
    combi = {}
    for i in range(N):
        t = ''.join(sorted(input()))
        
        if t not in combi.keys():
            
            combi[t] = 1
        else:
            combi[t] += 1

    ans = 0
    for v in combi.values():
        ans += combinations_count(v,2)
    print(ans)
if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import Counter as counter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,s):
    res = 0
    for i in counter(s).values():
        if 1 < i :
            res += int(i*(i-1)/2)
    print(res)

n = ii()
s = list("".join(sorted(input())) for _ in range(n))
main(n,s)

Solution (Python):
from collections import Counter

n = int(input())
sn = [None] * n
for i in range(n):
    sn[i] = ''.join(sorted(list(input().strip())))

c = Counter(sn)

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

print(ans)

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

Solution (Python):
import sys
import math
from collections import Counter
import itertools
import fractions



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

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

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")


 
N=II()
S=[''.join(sorted(SR())) for _ in range(N)]
C=Counter(S)
ans = 0
for c in C.values():
    if c>1:
        ans+=c*(c-1)/2
print(int(ans))

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



slist = []
countdic = {}


snum = ''.join(sorted(input()))






countdic[snum] = 0


for i in range(n-1):
    snum = "".join(sorted(input()))
    if snum not in countdic:
        countdic[snum] = 0
        
    else:
        countdic[snum] += 1
        
count_values =list(countdic.values())

count_values_len = len(count_values)


count_sum = 0
numtemp = 0

for i in range(count_values_len):
    count_values[i] = count_values[i] * (count_values[i]+1) / 2

print(int(sum(count_values)))

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

d = defaultdict(int)
ans = 0
for i in range(N):
  if s[i] in d.keys():
    ans += d[s[i]]
    d[s[i]] += 1
  else:
    d[s[i]] += 1

print(ans)

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

Solution (Python):
from collections import defaultdict
n = int(input())
li = []
for _ in range(n):
  s = input()
  temp = []
  dd = defaultdict(lambda:0)
  for i in s:
    dd[i] += 1
  for key in dd:
    temp.append((key, dd[key]))
  temp.sort()
  li.append(temp)
li.sort()
ans = 0
k = 0
for i in range(n):
  if i == n-1:
    ans += (k*(k+1))//2
  else:
    if li[i] == li[i+1]:
      k += 1
    else:
      ans += (k*(k+1))//2
      k = 0
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = [("").join(sorted(input().rstrip())) for i in range(N)]
    DICT = {}
    ans = 0
    for i in range(N):
        if S[i] in DICT:
            DICT[S[i]][1] += DICT[S[i]][0]
            DICT[S[i]][0] += 1
        else:
            DICT.setdefault(S[i], [1,0])
    for dicts in DICT:
        ans += DICT[dicts][1]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = [("").join(sorted(input().rstrip())) for i in range(N)]
    DICT = {}
    ans = 0
    for i in range(N):
        if S[i] in DICT:
            DICT[S[i]] += 1
            ans += DICT[S[i]]
        else:
            DICT.setdefault(S[i], 0)
    print(ans)

if __name__ == '__main__':
    main()

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

slist.sort()
slist += ['x']
a = slist[0]
ans = 0
count = 1
for s in slist[1:]:
  if a == s:
    count += 1
  else:
    if count > 1:
      ans += int(count*(count-1)/2)
    count = 1
    a = s
print(ans)

Solution (Python):
N = int(input())
strs = (input() for _ in range(0,N))

ans = {}
for string in strs:
    key = ''.join(sorted(string))
    if key not in ans:
        ans[key] = 0
    else:
        ans[key] += 1
print(sum([x*(x+1)//2 for x in ans.values()]))

Solution (Python):
from collections import Counter as CC
N = int(input())
L = [str(sorted(list(input()))) for i in range(N)]
C = CC(L)
print(sum([C[i] * (C[i] - 1) // 2 for i in C if C[i] > 1]))

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

dic = {}

for i in range(n):
    s = sorted(input())
    temp = "".join(s)
    if temp not in dic:
        dic[temp] = 1
    else:
        dic[temp] += 1
    
ans = 0
for i in dic.values():
    ans += i*(i-1)/2

print(int(ans))

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

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

Solution (Python):
from collections import Counter
a=int(input())
l=[]
l1=[]
p=0
for i in range(a):
    b=input()
    b=list(b)
    b=sorted(b)
    b="".join(map(str,b))
    l.append(b)
d=Counter(l)
for j in d:
        if d[j]<=2:
            p+=d[j]//2
        else:
            c=d[j]-1
            p+=(c*(c+1))//2
print(p)

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

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

Solution (Python):
from collections import defaultdict
def main(): 
    N = int(input())
    words = [ "".join(sorted(list(input()))) for i in range(N)]
    w = defaultdict(int)

    for word in words:
        w[word] += 1
        
    pair = 0
    for k, v in w.items():
        if v >= 2:
            pair += v*(v-1)//2
    
    print(pair)

if __name__ == "__main__":
    main()

Solution (Python):


import sys
input = sys.stdin.readline
N = int(input())
S = [input().strip() for i in range(N)]

from collections import Counter
c =[]
for i_s in S:
    i_sorted =sorted(i_s) 
    i="".join(i_sorted)
    c.append(i)

from collections import Counter
ans_colle =Counter(c) 
ans =0
for i in ans_colle.values():
    ans +=i*(i-1)//2
print(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):
from collections import defaultdict


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

Solution (Python):
n = int(input())
S = sorted([''.join(sorted(input())) for _ in range(n)])
t = len(set(S))
cnt = [1] * t
loop = 0

for i in range(0, t):
    for j in range(loop, n - 1):
        if S[j] == S[j + 1]:
            cnt[i] += 1
        else:
            loop = j + 1
            break


ans = 0
for i in range(0, t):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(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):
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)