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 i in range(N)]
mydict = {}
ans = 0
for i in S:
    if i in mydict:
        ans += mydict[i]
        mydict[i] += 1
    else:
        mydict[i] = 1

print(ans)

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

for i in range(n):
    s[i] = ''.join(sorted(s[i]))
d = {}
for i in range(n):
    if s[i] in d.keys():
        d[s[i]] += 1
    else:
        d[s[i]] = 1
print(sum(d[k] * (d[k] -1) // 2 for k in d))

Solution (Python):
from collections import Counter


def solve(string):
    n, *ss = string.split()
    d = Counter("".join(sorted(s)) for s in ss)
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from collections import Counter


def solve(string):
    n, *ss = string.split()
    d = Counter(s for s in map(lambda x: "".join(sorted(x)), ss))
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, *ss = string.split()
    d = {}
    for s in map(lambda x: "".join(sorted(x)), ss):
        d[s] = 1 + d[s] if s in d.keys() else 1
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)

Solution (Python):
def solve(string):
    n, *ss = string.split()
    d = {}
    for s in ss:
        s = "".join(sorted(s))
        d[s] = 1 + d[s] if s in d.keys() else 1
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

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

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

print(cnt)

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

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

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

Solution (Python):
N = int(input())
s_list = []
s_dict = {}
count = 0

for i in range(N):
  x = "".join(sorted(input()))
  if x not in s_dict:
    s_dict[x] = 0
  else:
    s_dict[x] += 1
    count += s_dict[x]

print(count)

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


for i in range (0,n):
    temp = 0
    linp =  sorted(input())
    inp = ''.join(linp)
    if inp in d:
        ans = ans + d[inp]
        d[inp] = d[inp] + 1
    else:
        d[inp] = 1
print(ans)

Solution (Python):
from collections import defaultdict


def solve(string):
    n, *s = string.split()
    d = defaultdict(int)
    for _s in s:
        d["".join(sorted(_s))] += 1
    return str(sum([v * (v - 1) // 2 for v in d.values() if v > 1]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n)+'\n'.join([input() for _ in range(n)])))

Solution (Python):
from functools import reduce

N = int(input())
dp = {}
result = 0

for _ in range(N):
    s = ''.join(sorted(input()))
    if s in dp:
        dp[s] += 1
    else:
        dp[s] = 1

print(reduce(lambda r, key: r + dp[key] * (dp[key] - 1) // 2, dp, 0))

Solution (Python):
import sys
 
N = int(input())
S = [''.join(sorted(input().rstrip())) for _ in range(N)]
 
from collections import Counter
counter = Counter(S)
 
answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

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

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

res = 0
d = dict()
for i in range(n):
    s = ''.join(sorted(input()))
    if s in d.keys():
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1

print(res)

Solution (Python):
import collections

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

ss_sorted = [''.join(sorted(s)) for s in ss]
cnts = collections.Counter(ss_sorted)

ans = 0
for key in cnts.keys():
    n = cnts[key]
    ans += n*(n-1)//2

print(ans)

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

n = int(input())


ss = []
checked = {}
count = 0
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = str(tmp)
    if not(tmp in checked):
        checked[tmp] = 1
    else:
        count += checked[tmp]
        checked[tmp] += 1

print(count)

Solution (Python):
N = int(input())
dic={}
for i in range(N):
    s = [x for x in str(input())]
    s.sort()
    _key="".join(s)
    if _key not in dic:
        dic[_key] = 1
    else:
        dic[_key] += 1
result=0      
for m in list(dic.values()):
  if m>1:
  	result+=m*(m-1)/2
print(int(result))

Solution (Python):
import collections

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

for i in range(n):
    s_in = str(input())
    s_in = list(s_in)
    s_in.sort()
    s_in = "".join(s_in)
    s[i] = s_in
    
s_col = collections.Counter(s)
s_set = set(s)

cnt = 0

for i in s_set:
    cnt += (s_col[i])*(s_col[i]-1)/2
print(int(cnt))

Solution (Python):
N = int(input())
c = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in c:
        c[s] = 0
    else:
        c[s] += 1
r = sum([(v/2)*(2 + v - 1) for v in c.values()])
print(int(r))

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



D = {}
for s in S:
    if not(s in D.keys()):
        D[s] = 1
    else:
        
        D[s] += 1


cnt = 0
for c in D.values():
    if c != 1:
        cnt += (c * (c - 1)) // 2

print (cnt)

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

i = 0
ans = 0
start = 0
while i<n:
    if s[start]!=s[i]:
        
        end = i-1
        ans += (1+end-start)*(end-start)//2
        start = i
    i += 1
ans += (n-start)*(n-1-start)//2
print(ans)

Solution (Python):
def main():
	n = int(input())
	sl=[]
	sl=["".join(sorted(input())) for _ in range(n)]
	sl.sort()
	b=""
	l=1
	ans=0
	for i, s in enumerate(sl):
		if s==b:
			l+=1
			if i==n-1 and l >1:
				ans+=l*(l-1)/2
		else:
			if l>1:
				ans+=l*(l-1)/2
			b=s
			l=1
	print (int(ans))

main()

Solution (Python):
def main():
	n = int(input())
	sl=[]
	sl=["".join(sorted(input())) for _ in range(n)]
	sl.sort()
	b=sl[0]
	l=1
	ans=0
	for i in range(1,n):
		if sl[i]==b:
			l+=1
			if i==n-1 and l >1:
				ans+=l*(l-1)/2
		else:
			if l>1:
				ans+=l*(l-1)/2
			b=sl[i]
			l=1
	print (int(ans))

main()

Solution (Python):

def green_bin(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        j = i + 1
        count = 1
        while j < N:
            if item == sorted_s[j]:
                count += 1
                j += 1
            else:
                break
        item_count.append(count)
        i += count  
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))

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

Solution (Python):
import math, heapq
from collections import defaultdict

INF = float("inf")
MOD = int(1e9 + 7)

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

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

count = 0
for c in ss.values():
    count += (c - 1) * c // 2
print(count)

Solution (Python):
n = int(input())
c = {}
for x in range(n):
    k = ''.join(sorted(input()))
    if k in c: c[k] += 1
    else: c[k] = 1
print(sum([n*(n-1)//2 for n in c.values() if n != 1]))

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

d = {}

for i in range(n):
  s = l[i]
  
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

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

Solution (Python):
import sys
import math
import bisect
import atexit
import io
import heapq
from collections import defaultdict, Counter
MOD = int(1e9+7)





def main():
    n = map(int, raw_input().split())[0]
    d = defaultdict(int)
    for i in range(n):
        s = raw_input()
        s = ''.join(sorted(s))
        d[s] += 1
    ans = 0
    for v in d.itervalues():
        if v > 1:
            ans += v * (v-1)/2
    print ans
main()

Solution (Python):
import sys
sys.setrecursionlimit(100000)
def intinput():return map(int,input().split())

n=int(input())
s={}
for i in range(n):
    t=list(input())
    t.sort()
    t="".join(t)
    try:
        s[t]+=1
    except:
        s[t]=1
ans=0
for i in s.values():
    if i!=1:
        ans+=i*(i-1)//2
print(ans)

Solution (Python):
N = int(input())
s_list=[]
s_dict={}
count=0

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

Solution (Python):
from itertools import groupby
from functools import reduce

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

def calc(x):
    return int(x*(x-1)/2)

g = list(map(lambda x: len(list(x[1])), groupby(sorted(Ss))))
h = list(map(calc, g))
res = sum(h)

print(res)

Solution (Python):
ll={}
c=0
for _ in range(int(input())):
    s="".join(sorted(input()))
    if s not in ll :
        ll[s]=0
    else:
        ll[s]+=1
        c+=ll[s]


print(c)

Solution (Python):
n = int(input())
arr = [input() for i in range(n)]
listarr = [[arr[i][j] for j in range(10)] for i in range(n)]
for i in range(n):
    listarr[i].sort()
tuplearrsort = [tuple(listarr[i]) for i in range(n)]
dic = {}

for i in range(n):
    if tuplearrsort[i] in dic:
        dic[tuplearrsort[i]] += 1
    else:
        dic[tuplearrsort[i]] = 1
      
count = 0
for key in dic:
    count += (dic[key] * (dic[key]-1)) // 2
    
print(count)

Solution (Python):
import collections

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

Solution (Python):
N = int(input())
o = {}
c = 0
for _ in range(N):
    k = "".join(sorted(input()))
    if k not in o:
        o[k] = 0
    else:
        o[k] += 1
        c += o[k]
print(c)

Solution (Python):
from collections import defaultdict

n=int(input())
dct=defaultdict(int)

for i in range(n):
  s=input()
  sort_s="".join(sorted(s))
  dct[sort_s]+=1
ans=0
for k,v in dct.items():
  ans+= v*(v-1)//2
print(ans)

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

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

L = []
c = 1
for i in range(N):
    if i == 0:
        pass
    else:
        if S[i-1]==S[i]:
            c += 1
            if i == N-1:
                L.append(c)
        else:
            if c >= 2:
                L.append(c)
            c = 1
res = 0
for x in L:
    res += cmb(x,2)
print(res)

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

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

L = []
c = 1
for i in range(N):
    if i == 0:
        pass
    else:
        if S[i-1]==S[i]:
            c += 1
            if i == N-1:
                L.append(c)
        else:
            if c >= 2:
                L.append(c)
            c = 1
res = 0
for x in L:
    res += cmb(x,2)
print(res)

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

d = {}
ans = 0

for j in str_lis:
    if j in d.keys():
        ans += d[j]
        d[j] += 1
    else:
        d[j] = 1
        
print(ans)

Solution (Python):
n = int(input())
strList = [input() for i in range(n)]

dict = {} 
for i in range(n):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  
 
count = 0;
for v in dict.values():
  count += (v * (v-1) // 2)
print(count)

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

count = 0

dict = {}

for i in range(N):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  


count = 0;
for v in dict.values():
  count += (v * (v-1) // 2)
print(count)

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

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

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

for l in range(N):
  S[l].sort()
  S[l] = ''.join(S[l]) 

S.sort()

X = []
p = 1

for j in range(N-1):
  if S[j] == S[j+1]:
    p +=1
  else:
    X.append(p)
    p = 1
X.append(p)


def comb(n):
  if n == 2: return 1
  else:
    return int(n*(n-1)/2)

ans = 0

for k in range(len(X)):
  ans += comb(X[k])

print(ans)

Solution (Python):
N=int(input())
D=dict()
for i in range(N):
    s=list(input())
    s.sort()
    s="".join(s)
    if s in D:
        D[s]+=1
    else:
        D[s]=1
        

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

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

cache = {}
cnt = 0
for s in strs:
  if s in cache.keys():
    cnt = cnt + cache[s]
    cache[s] = cache[s] + 1
  else:
    cache[s] = 1
print(cnt)

Solution (Python):
from collections import Counter
print(sum(v*(v-1)//2 for v in Counter(''.join(sorted(input())) for _ in range(int(input()))).values()))

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

Solution (Python):
N = int(input())
s = [input() for i in [0]*N]
words = {}
cnt = 0
for i in s:
    i = "".join(sorted(i))
    time = words.get(i,0)
    cnt += time
    words[i] = time + 1
print(cnt)

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ss = [''.join(sorted(stdin.readline().rstrip())) for _ in range(N)]
    spam = {}
    ans = 0
    for s in ss:
        if s in spam:
            ans += spam[s]
            spam[s] += 1
        else:
            spam[s] = 1
    print(ans)


if __name__ == "__main__":
    main()

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

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


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


sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    sortlist.append(a)
    
count=0


sortlist.sort()

checkword=""
check=0

for i in range(n): 
    a=sortlist.pop()
    if checkword==a:
            check+=1
            count+=check
    else:
        check=0
        checkword=a
    
print(int(count) )

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import collections
from math import factorial
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())
A = [str(input()) for _ in range(n)]
for i in range(len(A)):
    A[i] = "".join(sorted(A[i]))
A = sorted(A)
temp = A[0]
counter = 1
ans = 0
for i in range(1,len(A)):
    if temp != A[i]:
        if counter >= 2:
            
            ans += cmb(counter,2)
        temp = A[i]
        counter = 1
    else:
        counter += 1
if counter >= 2:
    
    ans += cmb(counter,2)
print(int(ans))

Solution (Python):
def main():
	n = int(input())
	sl=[]
	for i in range(n):
		sl.append(list(input()))
	for s in sl:
		s.sort()
	sl.sort()
	
	
	b=sl[0]
	l=1
	ans=0
	for i in range(1,n):
		if sl[i]==b:
			l+=1
			if i==n-1 and l >1:
				ans+=l*(l-1)/2
		else:
			if l>1:
				ans+=l*(l-1)/2
			b=sl[i]
			l=1
	print (int(ans))

main()

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

N = int(input())
L = [input().strip() for _ in range(N)]

m = [0 for _ in range(N)]
for i in range(N):
    p = list(L[i])
    p.sort()
    
    
    m[i] = "".join(p)

mm = {}
for i in range(N):
    if mm.get(m[i]) == None:
        mm[m[i]] = 0
    mm[m[i]] += 1


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

print(ans)

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

    ans = {}
    count = 0
    for s in strings:
        c = tuple(sorted(s))
        if c in ans:
            count += ans[c]
            ans[c] = ans[c] + 1
        else:
            ans[c] = 1

    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
n =int(input())
strl = [list(input()) for i in range(n)]

count =0
pt = {}
for i in range(n):
    sal = strl[i]
    sal.sort()
    temp = "".join(sal)
    if temp in pt.keys():
        tempc = pt[temp]
        count +=tempc
        pt[temp]= tempc+1
    else:
        pt[temp]= 1
print(count)

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

Solution (Python):
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    sDictionary = {}
    for i in range(n):
        if sDictionary.get(s[i]):
            ans += sDictionary.get(s[i])
            sDictionary[s[i]] += 1
        else:
            sDictionary[s[i]] = 1
    print(ans)


def SortString(text):
    return "".join(sorted(list(text)))


if __name__ == '__main__':
    main()

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

alphabets = [chr(ord('a')+i) for i in range(26)]
nums = defaultdict(int)
for s in S:
  ct = Counter(s)
  key = tuple([ct[al] for al in alphabets])
  nums[key] += 1

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

Solution (Python):
from collections import Counter

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

cnt = Counter(sss)

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

Solution (Python):
N = int(input())
sin = [input().strip() for i in range(N)]

def encode(dic):
    strs = 'abcdefghijklmnopqrstuvwxyz'
    key = ''
    for c in strs:
        num = str(dic[c]) if c in dic else '0'
        key += num + '_'
    return key

adic = {}
for s in sin:
    dic = {}
    for c in s:
        if c in dic:
            dic[c] += 1
        else:
            dic[c] = 1
    key = encode(dic)
    if key in adic:
        adic[key] += 1
    else:
        adic[key] = 1

ans = 0
for e in adic.values():
    ans += int(e * (e - 1) / 2)
print(ans)

Solution (Python):



from collections import Counter

def main():
  n = int(input())
  strings = Counter([''.join(sorted(input().strip())) for _ in range(n)])
  print(int(sum([v * (v-1) / 2 for _, v in strings.items()])))

if __name__=='__main__':
  main()

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

Solution (Python):

n=int(input())
strl=[list(input()) for i in range(n)]

count=0
pt={}

for i in range(n) :
  sal=strl[i]
  sal.sort()
  temp="".join(sal)
  if temp in pt.keys() :
    
    tempc=pt[temp]
    count+=tempc
    pt[temp]=tempc+1
  else :
    pt[temp]=1
print(count)

Solution (Python):
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    sDictionary = {}
    for i in range(n):
        if sDictionary.get(s[i]):
            ans += sDictionary.get(s[i])
            sDictionary[s[i]] += 1
        else:
            sDictionary[s[i]] = 1
    print(ans)


def SortString(text):
    return "".join(sorted(list(text)))


if __name__ == '__main__':
    main()

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

print(total)

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(s))
	if a in ctr :
		ans += ctr[a]
	ctr[a] += 1
print(ans)

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

dic = {}
ans = 0
for i in s:
    if i in dic:
        ans += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1
print(ans)

Solution (Python):
N = int(input())
str = [''.join(sorted(input())) for i in range(N)]
dict = {}
sum = 0

for i in range(N):
  try:
    dict[str[i]] += 1
  except KeyError:
    dict[str[i]] = 1

for i in dict.values():
  sum += (i*(i-1))//2

print(sum)

Solution (Python):
import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = {}

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    if y1 in ans_exa:
        ans_sum = ans_sum + ans_exa[y1]
        ans_exa[y1] = ans_exa[y1] + 1
    else:
         ans_exa[y1] = 1

print(ans_sum)

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

N = int(input())

result = 0
d = defaultdict(int)
for _ in range(N):
    s = input()
    s = ''.join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
print(sum([int((v)*(v-1) / 2) for k, v in d.items()]))

Solution (Python):


N = int(input())


dict = {}

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

    
    if s in dict:
        ans += dict[s]
        dict[s] += 1

    
    else:
        dict[s] = 1

print(ans)

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

s=sorted(s)

total=0
count=1
for j in range(1,n):
  if s[j]==s[j-1]:
    count = count+1
  else:
    if count>1:
      total = total+(count*(count-1))//2
    count=1

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

print(total)

Solution (Python):

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

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

print(cnt)

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
cnt = [i*(i-1)//2 for i in d.values()]
print(sum(cnt))

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
cnt = [i*(i-1)//2 for i in d.values()]
print(sum(cnt))

Solution (Python):
def clc(num):
  return int(1+num*(num-1)/2 +num-1)

n =int(input())
cnt=0
pr=0
s=[None]*n
ans=[0]*n
for i in range(n):
  s[i]=sorted(input())
s.sort()
for j in range(0, n-1, 1):
  if s[j] == s[j+1]:
    ans[cnt] += 1
  else:
    cnt +=1
clcnums = [clc(n) for n in ans if n!= 0]
print(sum(clcnums))

Solution (Python):
import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = 0

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()

for index in collections.Counter(moji).values():
  n = index - 1
  count += n*(1+n)/2

print(int(count))

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

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

Solution (Python):

import sys, math, fractions, itertools, collections


def solve(N: int, s: "List[str]"):
    S = []
    for ss in s:
        ss = sorted(ss)
        S.append(''.join(ss))
    c = list(collections.Counter(S).values())
    s = 0
    for cc in c:
        s += cc*(cc-1)//2
    print(s)
    return



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

if __name__ == '__main__':
    main()

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

Solution (Python):
char_num = int(input())
char_length = 10
chars = []
for i in range(char_num):
    chars.append(input())


class CharArrange:
    def __init__(self, char):
        self.char = char

    def char_run(self):
        list_char = self.str2ord_list(self.char)
        for pos in range(1, len(list_char)):
            self.insert_sort(list_char, pos, list_char[pos])
        self.char = self.ordList2Str(list_char)

    def order_run(self, chars):
        for i, char in enumerate(chars):
            chars[i] = self.ord_list2ord_concat(self.str2ord_list(char))
        for pos in range(len(chars)):
            self.insert_sort(chars, pos, chars[pos])
        self.ord_chars = chars

    def str2ord_list(self, char):
        return list(map(ord, char))

    def ordList2Str(self, ordList):
        return ''.join(list(map(chr, ordList)))

    def ord_list2ord_concat(self, ord_list):
        self.ord_concat = ''
        for ord_num in ord_list:
            self.ord_concat += str(ord_num)
        return int(self.ord_concat)

    def insert_sort(self, A, pos, value):
        i = pos - 1
        while (i >= 0 and A[i] > value):
            A[i+1] = A[i]
            i = i - 1
        A[i+1] = value
        return A


counter = 0
hash_table = {}
for i, char in enumerate(chars):
    CA = CharArrange(char)
    CA.char_run()
    if CA.char in hash_table:
        hash_table[CA.char] += 1
    else:
        hash_table[CA.char] = 0
    counter += hash_table[CA.char]


print(counter)

Solution (Python):
n = int(input())
 
l = []
for i in range(n):
	l.append(sorted(str(input())))
 
d = sorted(l)
c = 0
ans = 0
for i in range(n-1):
	if d[i] == d[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Solution (Python):
import math
def cmb(n, r):
        if r > n: 
                return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
 
import collections
N = int(input())
s= [input() for i in range(N)]
ans=0

s=list(map(sorted,s))
 
s.sort()        
s=list(map(''.join,s))  
clist = collections.Counter(s) 
kaisu=list(clist.values())
 
for i in kaisu:
        ans += cmb(i,2)
 
print(ans)

Solution (Python):
import math
def cmb(n, r):
        if r > n: 
                return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


import collections
N = int(input())
s= [input() for i in range(N)]
ans=0

s=list(map(sorted,s))

s.sort()        
s=list(map(''.join,s))  
clist = collections.Counter(s) 
kaisu=list(clist.values())

for i in kaisu:
        ans += cmb(i,2)

print(ans)

Solution (Python):
from collections import defaultdict
a = int(input())
dic = defaultdict(int)
l = []
for i in range(a):
    l.append("".join(sorted(list(input()))))
    dic[l[-1]]+=1
s = 0
L = set(l)
for j in L:
    i = dic[j]
    s+=i*(i-1)/2
print(int(s))