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=[''.join(sorted(input()))for _ in range(N)]

from collections import*
C=Counter(S)

print(sum(v*(v-1)//2 for v in C.values()))

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

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

D = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
            
print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for i in range(n):
        s1 = list(input())
        d[tuple(sorted(s1))] += 1
    ans = 0
    for i in d.values():
        ans += i*(i-1)//2
    print(ans)

    return

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
dic=dict()
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s in dic:
    dic[s] += 1
  else:
    dic[s]=1
res = sum([x*(x-1)//2 for x in dic.values() if x > 1])
print(res)

Solution (Python):
n=int(input())
dic=dict()
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s in dic:
    dic[s] += 1
  else:
    dic[s]=1
res = sum([x*(x-1)//2 for x in dic.values() if x > 1])
print(res)

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

c = Counter(s)

l = sum((v*(v-1)/2) for v in c.values())
print(int(l))

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

c = Counter(s)

l = sum((v*(v-1)/2) for v in c.values())
print(int(l))

Solution (Python):
from collections import Counter

def check(s1, s2):
	for i in range(26):
		if s1[i] != s2[i]:
			return False;
	return True

n = int(input())
stuff = []
for _ in range(n):
	d = list(input())
	cnt = [0 for x in range(26)]
	for i in range(10):
		cnt[ord(d[i])-97] += 1
	stuff.append(cnt)

stuff.sort()
span = 1
ans = 0
for i in range(n-1):
	if check(stuff[i+1], stuff[i]):
		span += 1
	else:
		ans += span*(span-1)//2	
		span = 1
ans += span*(span-1)//2
print(ans)

Solution (Python):
def main():
    n = int(input())
    s = [list(input()) for i in range(n)]
    d = {}
    ans = 0
    for i in s:
        ss = ''.join(sorted(i))
        if ss not in d:
            d.setdefault(ss, 1)
        else:
            d[ss] = d.get(ss) + 1
    for k, v in d.items():
        ans += round(v*(v-1)/2)
    print(ans)
    
if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter

def MI():
    return map(int, input().split())

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

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

for s in S:
    tmp = []
    si = Counter(s)
    for l, c in si.items():
        tmp.append((l, c))
    tmp.sort(key = lambda x : x[0])
    cnt.append(tuple(tmp))
 
cnt = Counter(cnt)
ans = 0

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

print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    s = input()
    ss = sorted(s)
    S.append("".join(ss))
S.sort()
ans = 0
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
        ans += count
    else:
        count = 0
print(ans)

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

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

word = {}
for i in range(N):
    t = list(input())
    t.sort()
    t = "".join(t)
    if t not in word:
        word[t] = 1
    else:
        word[t] += 1

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

print(ans)

Solution (Python):
n = int(input())
s = [''.join(sorted(list(input()))) for x in range(n)]
ans = 0
s_dict = dict()
for v in s:
    if v in s_dict:
      ans += s_dict[v]
      s_dict[v] += 1
    else:
        s_dict[v] = 1
print(ans)

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

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

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

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

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

Solution (Python):
n=int(input())
from collections import Counter
s=[]
for i in range(n):
  read=list(input())
  read.sort()
  s.append("".join(read))

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

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

s = [sorted(list(input())) for _ in range(n)]
s_e = [''] * n

for i in range(n):
    s_e[i] = ''.join(s[i])

s_e.sort()


count = 1
ans = 0

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

if count > 1:
    ans += (count * (count-1) // 2)

print(ans)

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

Solution (Python):
from collections import defaultdict
n=int(input())
d=defaultdict(int)
S=[input() for _ in range(n)]
for i in range(n):
    S[i] = ''.join(sorted(S[i]))
    d[S[i]]+=1

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

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

sentence_count_dict = {}
for _ in range(N):
    sentence = list(input())
    sentence = ''.join(sorted(sentence))
    if sentence in sentence_count_dict:
        sentence_count_dict[sentence] += 1
    else:
        sentence_count_dict[sentence] = 1

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

print(int(total))

Solution (Python):
def nC2(n):
    if n < 2:
        return 0
    return n * (n-1) // 2

def main():
    N = int(input())
    S = [''.join(sorted(input())) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()

Solution (Python):

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

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

for i in dictionary.values():
    if(i >= 2):
        count += combinations_count(i, 2)

print(count)

Solution (Python):
N = int(input())
s = sorted([sorted(input()) for _ in range(N)])
total = 0
count = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        total += count * (count - 1) / 2
        count = 1
total += count * (count - 1) / 2
print(int(total))

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

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

Solution (Python):
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    if value>=2:
        ans+=combinations(value,2)
print(ans)

Solution (Python):
import collections

N = int(input())

s = [''] * N

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

c = collections.Counter(s)

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
l = []
m = []
for _ in range(N):
    data = input()
    data = list(data)
    data.sort()
    l.append(data)
l.sort()
cnt = 0
for i in range(N-1):
    if l[i] == l[i+1]:
        cnt += 1
    else:
        if cnt == 0:
            pass
        else:
            m.append(cnt+1)
        cnt = 0
if cnt != 0:
    m.append(cnt+1)

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

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

for _ in range(n):
    s = sorted(input())
    sn.append("".join(s))

import collections
c = collections.Counter(sn)

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

print(ans)

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

s.sort()

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

if cnt > 1:
  ans += (cnt * (cnt -1) )/2
print(int(ans))

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

from collections import Counter

L = [''.join(sorted(list(s))) for s in S]
C = Counter(L)
ans = 0
for i in C.values():
    ans += i*(i-1)//2
print(ans)

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

from collections import Counter

H = [hash(''.join(sorted(list(s)))) for s in S]
C = Counter(H)

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

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

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

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

cnt = 0
for k in mydict:
	num = mydict[k]
	cnt = cnt + (num*(num-1))//2

print(cnt)

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

for i in range(N) :
    s = tuple(sorted(input()))
    if s in dic :
        ans += dic[s]
        dic[s] += 1
    else : 
        dic[s] = 1

print(ans)

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

l = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    l.append(tmp)

from collections import Counter
c = Counter(l)
num = sorted(list(c.values()), reverse = 1)

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

ans = 0
for i in num:
    if i == 1:
        break
    else:
        ans += combinations_count(i, 2)

print(ans)

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

l = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    l.append(tmp)

from collections import Counter
c = Counter(l)
num = tuple(c.values())

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

ans = 0
for i in num:
    if i > 1:
        ans += combinations_count(i, 2)

print(ans)

Solution (Python):
N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1
 
ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += sum(iL)
    
print(ans)

Solution (Python):
N = int(input())
 
dic = {}
ans = 0
for i in range(N):
    s = tuple(sorted(input()))
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)

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

l = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    l.append(tmp)

from collections import Counter
c = Counter(l)
num = list(c.values())

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

ans = 0
for i in num:
    if i > 1:
        ans += combinations_count(i, 2)

print(ans)

Solution (Python):
from collections import defaultdict

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

res = 0
d = defaultdict(int)
for list_ in s:
    str_ = str(list_)
    d[str_] += 1
    res += d[str_] - 1

print(res)

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

res = 0
d = dict()
for list_ in s:
    str_ = str(list_)
    if str_ in d:
        d[str_] += 1
        res += d[str_] - 1
    else:
        d[str_] = 1

print(res)

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

res = 0
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        res += cnt
        cnt += 1
    else:
        cnt = 1

print(res)

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


S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L

S.sort()

goukei=0
banpei=S[0]
ncr=1
for i in range(1,N):
    if banpei==S[i]:
        ncr+=1
    else:
        if ncr>=2:
            goukei+=(ncr*(ncr-1))//2
        ncr=1
        banpei=S[i]

if ncr>=2:
    goukei+=(ncr*(ncr-1))//2 
    

print(goukei)

Solution (Python):
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
d = {}
for i in range(N):
    a = list(s[i][:])
    b = ''.join(sorted(a))
    if b in d:
        d[b]+=1
    else:
        d[b]=1
ans = 0
for j in d.values():
    ans+=j*(j-1)//2
print(ans)

Solution (Python):
import collections
import math
n = int(input())
a = [0]*n
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(input())
    t.sort()
    m = " ".join(t)
    a[j] = m
c = collections.Counter(a)
d = list(c)
for k in range(len(d)):
    if c[d[k]] > 1:
        b += combinations_count(c[d[k]], 2)
    else:
        continue
print(b)

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

Solution (Python):
import collections
N=int(input())
SS=[]
answer=0
for _ in range(N):
    s=input()
    s=sorted(s)
    S=''
    for a in s:
        S+=a
    SS.append(S)
a=collections.Counter(SS)
for n in a.values():
   answer+=(n-1)*n/2
print(int(answer))

Solution (Python):
def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for v in d.values():
            ans += (v*(v-1)) // 2
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for k, v in d.items():
        if v != 1:
            ans += (v*(v-1)) // 2
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

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

Solution (Python):
import math


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


def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for k, v in d.items():
        if v != 1:
            ans += combinations_count(v, 2)
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1

ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += sum(iL)
    
print(ans)

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

Solution (Python):
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") 

n = int(input())

data = {}
for _ in range(n):
    temp = "".join(sorted(input()))
    
    if temp in data.keys():
        data[temp] += 1
    else:
        data[temp] = 1


answer = 0
for num in data.values():
    answer += (num*(num-1))//2
print(answer)

Solution (Python):
n = int(input())
from collections import Counter
cnt= 0
L = []
for i in range(n):
    s = sorted(input())
    L.append(("".join(s)))

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

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

dic={}
cnt=0
for i in range(n):
    s=tuple(sorted(input()))
    if s in dic:
        cnt+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(cnt)

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

for _ in range(N):
  s = input()
  alpha = [0] * 26
  a = ord("a")
  for c in s:
    alpha[ord(c)-a] += 1 
  counter[tuple(alpha)] += 1

res = 0
for k,v in counter.items():
  res +=v*(v-1)//2

print(res)

Solution (Python):
N = int(input())
s = {}
for _ in range(N):
    input_s = list(input())
    input_s = sorted(input_s)
    input_s = "".join(input_s)
    if input_s not in s.keys():
        s[input_s] = 0
    s[input_s] += 1
ans = 0
for key, value in s.items():
    if value >= 2:
        ans += value * (value - 1) // 2
print(ans)

Solution (Python):
import sys

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


def solve():
    N = int(input())
    d = dict()

    for _ in range(N):
        s = str(sorted(input()))
        if s in d:
            d[s] += 1
        else:
            d[s] = 1

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

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import math
def comb(n, r):
  if n - r >= 0:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0
N = int(input())
string = {}
res = 0
for i in range(N):
  s = str(sorted(input()))
  if s in string:
    string[s] += 1
  else:
    string[s] = 0
for key in string:
  res += comb(string[key] + 1, 2)
print(res)

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


count = 0
hashset = {}

for i in range(len(S)):
    key = ''.join(sorted(S[i]))
    if key in hashset:
        count += hashset[key]
        hashset[key] += 1
    else:
        hashset[key] = 1

print(count)

Solution (Python):



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

dic = {}
for s in S:
    s = list(s)
    s.sort()
    s = ''.join(s)
    if not s in dic:
        dic[s] = 1
        continue
    dic[s] += 1

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

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

A=[]
for i in range(n):
    s=sorted(input())
    t=''.join(s)
    A.append(t)

r=collections.Counter(A)
r=r.most_common()

cnt=0
for j in range(len(r)):
    if r[j][1]==1:
        cnt+=0
    else:
        cnt+=((r[j][1]-1)*r[j][1])//2
print(cnt)

Solution (Python):
n = int(input())
import collections
d = collections.defaultdict(int)
ans = 0
for i in range(n):
    sl = sorted([j for j in input()])
    ss = ''.join(sl)
    ans += d[ss]
    d[ss] += 1

print(ans)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *

from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]







n=l()[0]
A=[list(input()) for i in range(n)]
d={}
for i in range(n):
    x=tuple(sorted(A[i]))
    if(x not in d):
        d[x]=0
    d[x]+=1
ans=0
for ks in d:
    ans+=(d[ks]*(d[ks]-1)//2)
print(ans)

Solution (Python):
import collections

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

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict

def nC2(n):
    return n * (n - 1) // 2

n = int(input())
d = defaultdict(int)
for _ in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    d[s] += 1

ans = 0
for k, v in d.items():
    ans += nC2(v)
print(ans)

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

from operator import mul
from functools import reduce
from collections import Counter

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(readline())
s = ["".join(sorted(list(readline().decode().rstrip()))) for _ in range(n)]

c = Counter(s)

l = [cmb(v,2) for k, v in c.items() if v >=2]
print(sum(l))

Solution (Python):
import collections

n = int(input())

lis = ["".join(sorted(input())) for _ in range(n)]
    
c = collections.Counter(lis)

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

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

ans = 0
counter_list = []

for _ in range(N):
    s = input()
    counter_list.append("".join(sorted(s)))

ans = 0
wordcount = {}
for word in counter_list:
    if word in wordcount:
        wordcount[word] += 1
        ans += (wordcount[word])
    else:
        wordcount[word] = 0

print(ans)

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

ans = 0
counter_list = []

for _ in range(N):
    s = input()
    counter_list.append("".join(sorted(s)))

ans = 0
wordcount = {}
for word in counter_list:
    if word in wordcount:
        wordcount[word] += 1
        ans += (wordcount[word])
    else:
        wordcount[word] = 0

print(ans)

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

Solution (Python):
from collections import defaultdict

N = int(input())
ans = 0
d = {}
for _ in range(N):
    s = sorted(input())
    s = "".join(s)
    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())
d = defaultdict(int)
for i in range(n):
  s = tuple(sorted(list(input())))
  d[s] += 1

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = [list(input().strip("\n")) for _ in range(N)]
    for i in range(N): S[i].sort()
    S.sort()
    S.append(["E", "N", "D"])

    ans = 0
    current = "".join(S[0])
    same = 0
    for i in range(1, N+1):
        tempS = "".join(S[i])
        if tempS == current:
            same += 1
        else:
            ans += (1 + same) * same // 2
            same = 0
            current = tempS
    print(ans)

    return  0

if __name__ == "__main__":
    solve()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

from itertools import permutations
from math import factorial, hypot





N = getN()
S = [''.join(sorted(list(input()))) for i in range(N)]
ans = 0
for i in Counter(S).items():
    ans += i[1] * (i[1] - 1) // 2
print(ans)

Solution (Python):
N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
S = sorted(S)
a = 'sing'
for j in range(N):
    if a != S[j]:
        f = 0
        a = S[j]
    else:
        f += 1
        count += f
print(count)

Solution (Python):
N = int(input())
memo = {}
for _ in range(N):
    si = sorted(list(input()))
    si = "".join(si)
    try:
        memo[si] += 1
    except:
        memo[si] = 1


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


ans = 0
for key in memo.keys():
    ans += combinations_count(memo[key],2)

print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = [''.join(sorted(list(input()[:-1].decode()))) for _ in range(n)]

    nc2 = [i * (i - 1) // 2 for i in range(10 ** 5 + 1)]

    summary = {}

    for si in s:
        if si in summary:
            summary[si] += 1
        else:
            summary[si] = 1

    ans = 0

    for si in summary:
        ans += nc2[summary[si]]

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
import collections
n ,res, cc = int(raw_input()),0,collections.Counter()
while(n):
	u =  tuple(sorted(raw_input()))
	res += cc[u]
	n-=1
	cc[u]+=1
print res

Solution (Python):
from collections import Counter

N = int(input())
S = list(sorted([sorted(input()) for i in range(N)]))
mini_count = 0
count = 0
tmp = S[0]

for i in range(1, N):
    if tmp == S[i]:
        mini_count += 1
        count += mini_count
    else:
        tmp = S[i]
        mini_count = 0

print(count)

Solution (Python):
n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
d={}
ans = 0
for i in s:
	k = d.get(i, 0)
	ans += k
	if k == 0:
		d[i] = 1
	else:
		d[i] += 1
print(ans)

Solution (Python):
import math
import collections
n=int(input())
s=[sorted(input()) for _ in range(n)]
c=[str(collections.Counter(s[i])) for i in range(n)]
k=collections.Counter(c).values()
ans = 0
for i in k:
	if i >= 2:
		ans += math.factorial(i)//2//math.factorial(i-2)
print(ans)

Solution (Python):
N=int(input())
dict={}
cnt=0
for a in range(N):
  s="".join(sorted(input()))
  if s in dict:
    dict[s]+=1
    cnt+=dict[s]
  else:
    dict[s]=0
print(cnt)

Solution (Python):

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


ans = 0
cnt = 1
for i in range(n):
  if s[i] == s[i+1]:
    cnt += 1
  if cnt > 1 and s[i] != s[i+1]:
    ans += cnt * (cnt-1) // 2
    cnt = 1


print(ans)

Solution (Python):
import itertools

n = int(input())

s = [0 for _ in range(n)]
in_a = [0 for _ in range(n)]
dic_tmp = {}
dic_ar = [0 for _ in range(n)]
for i in range(n):
    in_a[i] = input()

cnt = 0
for i in range(n):
    s = sorted(in_a[i])
    s = "".join(s)
    if(s in dic_tmp):
        cnt += dic_tmp[s]
        dic_tmp[s] += 1
    else:
        dic_tmp[s] = 1

print(cnt)

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

S = [""]*N

for i in range(N):
    S[i] = input()
    
def cmb(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
  
  
S_set = ["".join(sorted(s)) for s in S]


import collections
import itertools

same_list = collections.Counter(S_set)

ans = [0]*len(same_list)

for i,v in enumerate(same_list.values()):
    if i==0:
        if v==1:
            ans[i] = 0
        else:
            ans[i] = cmb(v, 2)
    else:
        if v==1:
            ans[i] = ans[i-1] + 0
        else:
            ans[i] = ans[i-1] + cmb(v, 2)

print(ans[-1])

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

Solution (Python):
import collections

n=int(input())

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

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

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

print(cnt)