Problem:
 Score : 300 points    Problem Statement We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a .  For example, greenbin is an anagram of beginner . As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N . Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j  (1 \leq i < j \leq N) such that s_i is an anagram of s_j .      Constraints  2 \leq N \leq 10^5  s_i is a string of length 10 .  Each character in s_i is a lowercase English letter.  s_1, s_2, \ldots, s_N are all distinct.         Input Input is given from Standard Input in the following format:  N  s_1  s_2  :  s_N       Output Print the number of pairs of integers i, j  (1 \leq i < j \leq N) such that s_i is an anagram of s_j .        Sample Input 1 3
acornistnt
peanutbomb
constraint      Sample Output 1 1  s_1 =  acornistnt is an anagram of s_3 =  constraint . There are no other pairs i, j such that s_i is an anagram of s_j , so the answer is 1 .       Sample Input 2 2
oneplustwo
ninemodsix      Sample Output 2 0  If there is no pair i, j such that s_i is an anagram of s_j , print 0 .       Sample Input 3 5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa      Sample Output 3 4  Note that the answer may not fit into a 32 -bit integer type, though we cannot put such a case here.

Solution (Python):
from collections import Counter
import math


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


n = int(input())
s = []
for i in range(n):
    s.append("".join(sorted(input())))
c = Counter(s).most_common()
ans = 0
for i in c:
    if i[1] > 1:
        ans += nCr(i[1], 2)
print(ans)

Solution (Python):
N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(N):
    k=list(l[x])
    k.sort()
    k=''.join(k)
    l[x]=k
l.sort()
k=1
ans=0
for i in range(N-1):
    if l[i]==l[i+1]:
        k+=1
    else:
        ans+=k*(k-1)//2
        k=1
ans+=k*(k-1)//2
print(ans)

Solution (Python):
import math

n=int(input())
L={}
for i in range(n):
    s="".join(sorted(list(input())))
    if s not in L.keys():
        L[s]=1
    else:
        L[s]+=1

ans=0
for v in L.values():
    if v!=1:
        ans += math.factorial(v)/(math.factorial(2)*math.factorial(v-2))
print(int(ans))

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

for i in range(N):
    num = cnt.get(S[i], 0)
    ans += num
    cnt[S[i]] = num + 1

print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())
history = {}
ans = 0

for i in range(N):
    sorted_s = ''.join(sorted(S[i]))
    num = history.get(sorted_s, 0)
    ans += num
    history[sorted_s] = num + 1

print(ans)

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )



from operator import mul
from functools import reduce

def combinations_count(n, r):
    if n<r:
        return 0
    else:
        r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random

def main():
    n = int(input().strip())
    dict_S = {}
    for i in range(n):
        S = input().strip()
        
        S="".join(sorted(S))
        

        
        if S in dict_S:
            dict_S[S]+=1
        else: 
            dict_S[S]=1
    
    ans=0
    
    
    
    
    
    
    
    
        
    for key,value in dict_S.items():
        ans+=combinations_count(value,2)
    print(ans)
    return

if __name__ == '__main__':
    main()

    

'''

given N (2<=N<=10^5)
given [s_{i}] 
	(0<=i<=N-1)
	(\forall i \in {0...(N-1)}, len(s_{i})==10 )
	
	( \forall (i,j) \in {0...(N-1)}^{2} and 0<=i<j<=(N-1), s_{i} != s_{j} )
	
	

'''

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

Solution (Python):
N = int(input())
lst = [''.join(sorted(input().rstrip())) for i in range(N)]

ans = 0
dic = {}

for i in lst:
    if i in dic:
        ans += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1
print(ans)

Solution (Python):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)

N = int(input())

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

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

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

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

count = {}
ans = 0

for s in S:
    s=str(sorted(s))
    if s in count:
        count[s] += 1
    else:
        count[s] = 1

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

Solution (Python):

import sys
input = sys.stdin.readline

def cmb(n, r):
    if n - r < r: r = n - r
    if n == 1: return 0
    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
 
N = int(input())
table = {}
cache = {}
for x in range(N):
    s = ''.join(sorted(list(input())))
    s = s.strip()
    if s in table:
        table[s] = table[s] + 1
    else:
        table[s] = 1

ans = 0
for x in table:
    if table[x] not in cache:
        p = cmb(table[x], 2)
        cache[x] = p
    ans = ans + cache[x]
    
print(ans)

Solution (Python):
N=int(input())
d={}
for i in range(N):
  a = "".join(sorted(list(input())))
  if a not in d:
    d[a] = 1
  else:
    d[a]=d[a]+1
cnt = 0
for B in d.values():
  cnt += int(B * (B-1) /2)
print(cnt)

Solution (Python):
def ccc(n):
    
    result = (n * (n-1))//2
    return result



def sortString(a):
    a = list(a)
    a.sort()
    return "".join(a)


def calculate(arr):
    if len(arr) == 0:
        return 0

    dict = {}
    for i in range(len(arr)):
        s = sortString(arr[i])
        if dict.get(s) == None:
            dict.setdefault(s,1)
        else:
            dict.__setitem__(s,dict.get(s) + 1)


    sum = 0
    for v in dict.values():
        sum += ccc(v)

    return sum



arr = []

N = int(input())
for i in range(N):
    arr.append(input())


result = calculate(arr)
print(result)

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

from collections import Counter

cs = Counter(["".join(sorted(_)) for _ in S])

result = 0
for c, n in cs.items():
    result += n * (n - 1) // 2

print(result)

Solution (Python):
N = int(input())
S = sorted(''.join(sorted(list(input()))) for i in range(N))

ans = 0
sep = []
for i in range(N-1): 
    if  S[i] != S[i+1]:
        sep.append(i+1)
sep.append(N)

count = []
prev = 0
for i in sep: 
    count.append(i-prev)
    prev = i

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

Solution (Python):
import collections

n = int(input())

cnt = collections.Counter(["".join(sorted(input())) for i in range(n)])

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

print(ans)

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

D = dict()
for i in range(N):
    a = input()
    a = ''.join(sorted(a))
    if a in D:
        D[a] = D[a]+1
    else:
        D[a] = 1

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

print(ans)

Solution (Python):
import collections
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
ans = 0

c = collections.Counter(s)
for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)

Solution (Python):
import collections
n = int(input())
s = [[0 for j in range(10)] for i in range(n)]
for i in range(n):
    t = input()
    s[i] = "".join(sorted(t))
ans = 0

c = collections.Counter(s)
for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)

Solution (Python):
import collections
n = int(input())
s = [[0 for j in range(10)] for i in range(n)]
for i in range(n):
    t = input()
    s[i] = "".join(sorted(t))
s.sort()
ans = 0

c = collections.Counter(s)
for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)

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

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
  n = input()
  n = int(n)
  x = []
  for i in range(n):
    l = input()
    x.append(''.join(sorted(l)))

  c = collections.Counter(x)
  values, counts = zip(*c.most_common())
  sum = 0
  for i in range(len(counts)):
    if counts[i] > 1:
      sum += C(counts[i], 2)
  print(sum)


if __name__ == '__main__':
    main()

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

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
  n = input()
  n = int(n)
  x = []
  for i in range(n):
    l = input()
    x.append(''.join(sorted(l)))

  c = collections.Counter(x)
  values, counts = zip(*c.most_common())
  sum = 0
  for i in range(len(counts)):
    if counts[i] > 1:
      sum += C(counts[i], 2)
  print(sum)


if __name__ == '__main__':
    main()

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

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = input()
n = int(n)
x = []
for i in range(n):
  l = input()
  x.append(''.join(sorted(l)))

c = collections.Counter(x)
values, counts = zip(*c.most_common())
sum = 0
for i in range(len(counts)):
  if counts[i] > 1:
    sum += C(counts[i], 2)

print(sum)

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

for i in range(n):
    s = ''
    list = sorted(input())
    for j in list:
        s += j
    if i != 0 and s in dict.keys():
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1

print(ans)

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

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = input()
n = int(n)
x = []
for i in range(n):
  l = input()
  x.append(''.join(sorted(l)))

c = collections.Counter(x)
values, counts = zip(*c.most_common())
sum = 0
for i in range(len(counts)):
  if counts[i] > 1:
    sum += C(counts[i], 2)

print(sum)

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

for i in range(n):
  a=input()
  newa="".join(sorted(a))
  dict[newa]=dict.get(newa,0)+1

ans=0

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

print(int(ans))

Solution (Python):
from collections import defaultdict
N=int(input())
S={}
S_counter = defaultdict(int)
count=0
for i in range(N):
  s="".join(sorted(input()))
  if s in S:
    count += S[s]
    S[s] += 1
  else:
    dict={s:1}
    S.update(dict)
print(count)

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


for i in range(n):
    s[i]=sorted(s[i])

s=sorted(s)

ans=0
pos=0
while pos<=n-1:
    c=1
    while pos<=n-2 and s[pos]==s[pos+1]:
        c+=1
        pos+=1
    pos+=1
    ans+=c*(c-1)//2
print(ans)

Solution (Python):
n=int(input())
import math
d={}
for i in range(n):
    a="".join(sorted(input()))
    if a not in d:
        d[a]=1
    else:
        d[a]+=1
ans=0
for i in d.values():
  ans+=i*(i-1)//2
print(ans)

Solution (Python):
def main():
    s = ["".join(sorted(i)) for i in open(0).read().split()[1:]]
    ans = 0
    d = {}
    for i in s:
        if i in d:
            ans += d[i]
            d[i] += 1
        else:
            d[i] = 1
    print(ans)
    return


main()

Solution (Python):
from collections import defaultdict


def main():
    s = map(lambda x: "".join(sorted(x)), open(0).read().split()[1:])
    d = defaultdict(lambda: 0)
    ans = 0
    for i in s:
        ans += d[i]
        d[i] += 1
    print(ans)
    return


main()

Solution (Python):
from collections import defaultdict


def main():
    s = ("".join(sorted(i)) for i in open(0).read().split()[1:])
    d = defaultdict(lambda: 0)
    ans = 0
    for i in s:
        ans += d[i]
        d[i] += 1
    print(ans)
    return


main()

Solution (Python):
from collections import defaultdict


def main():
    s = [tuple(sorted(i)) for i in open(0).read().split()[1:]]
    d = defaultdict(lambda: 0)
    ans = 0
    for i in s:
        ans += d[i]
        d[i] += 1
    print(ans)
    return


main()

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


def cmb(n, r):
    if n < r:
        return 0
    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


def main():
    n = int(input())
    s_list = []
    for i in range(n):
        temp_s = sorted(list(input()))
        s_list.append(''.join(temp_s))

    counter = collections.Counter(s_list)
    ans = 0
    for key, value in counter.items():
        temp = cmb(value, 2)
        ans += temp


    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    

    n = int(input())
    wow = dict()
    for _ in range(n):
        s = list(input()[:-1])
        s.sort()
        s = str(s)
        if wow.get(s) == None:
            wow[s] = 0
        wow[s] += 1
    

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    ans = 0
    for i in wow.values():
        
        if i == 1:
            continue
        ans += combinations_count(i, 2)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 0
    d[s] += 1



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

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


print(ans)

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

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

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

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

d = Counter(li)
L = list(d.values())

cnt = 0
for i in range(len(L)):
    cnt += L[i]*(L[i]-1)//2
print(cnt)

Solution (Python):
from collections import Counter
N = int(input())
slist = ["".join(sorted(list(input()))) for _ in range(N)]
c = Counter(slist)
ans = 0
for v in c.values():
    ans += sum(range(v))
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
ans = 0
ctr = Counter()

for i in range(n):
  s = ''.join(sorted(list(input())))
  if s in ctr:
    ans += ctr[s]
  ctr[s] += 1
  
print(ans)

Solution (Python):
import math

n = int(input())
s = sorted(["".join(sorted(input())) for i in range(n)])
a = 0
b = []
for i in range(n-1):
  if s[i]==s[i+1]:
    a += 1
  else:
    a = 0
  b.append(a)
print(sum(b))

Solution (Python):
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial
def com(n,r):
  if n<r:
    return 0
  return int(factorial(n) // factorial(r) // factorial(n-r))

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

for _ in range(n):
  l=sorted(input())
  l_list.append(l)

l_list = sorted(l_list)

count=0

ans = 0
i = 0
j = 1
while i < n:
  tmp = 0
  while i + j < n and l_list[i] == l_list[i + j]:
    tmp += 1
    j += 1
  if tmp != 0:
    ans += com(tmp+1, 2)
  i += j
  j = 1

print(ans)

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




sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 1

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

Solution (Python):
from collections import Counter

n = int(input())
s={}

for _ in range(n):
    ss = str(sorted(input()))
    if ss not in s:
        s[ss] = 1
    else:
        s[ss] += 1

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

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

num_list = []
itr=0

while itr < N:
    num=1
    for tgt in range(itr+1, N):
        
        if sentence[itr]==sentence[tgt]:
            num += 1
            if tgt == N-1:
                num_list.append(num)
                itr=tgt
        else:
            num_list.append(num)
            itr = tgt
            break
    if itr==N-1:
        break

result = 0
if len(num_list)>0:
    for num in num_list:
        result += num*(num-1)//2
print(result)

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

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

Solution (Python):
import sys
import collections
from functools import reduce
import operator as op


def nCr(n,r):
    r = min(r,n-r)
    """ operator.mul = 掛け算を行う関数"""
    """引数の２つ目は先頭を示す"""
    up = reduce(op.mul,range(n,n-r,-1),1)
    down= reduce(op.mul,range(r,0,-1),1)
    return up // down

def main():
    n = int(sys.stdin.readline().rstrip())
    
    sorted_letters =[''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]

    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >=2:
            count +=nCr(c,2)
        
    
    print(count)
    
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
l = sorted([sorted(list(input())) for i in range(n)])
ans = []
las = l[0]
count = 1
for i in range(1,n):
    if las == l[i]:
        count += 1
    else:
        ans.append(count)
        count = 1
        las = l[i]
if sum(ans) != n:
    ans.append(count)

a = 0
for i in range(len(ans)):
    if ans[i] != 1:
        for j in range(1,ans[i]):    
            a += j
print(a)

Solution (Python):
n=int(input())
d=[]
for i in range(n):
  s=list(input())
  s.sort()
  s="".join(s)
  d.append(s)
d.sort()
x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

ans=[]
for i in range(len(x)):
  if x[i]>1:
    ans.append((x[i]*(x[i]-1))/2)
  else:
    ans.append(0)
    
    
print(int(sum(ans)))

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

ans = 0
aDict = {}
for i in s:
  if str(i) not in aDict:
    aDict[str(i)] = 1
  else:
  	aDict[str(i)] += 1
    
for n in aDict.values():
    ans += (n*(n-1)//2)
print(ans)

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

d = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
       d[s] = 0
    d[s] += 1

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

print(ans)

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

main()

Solution (Python):
import math
n = int(input())
a = list()
d = dict()
for i in range(n):
    b = list(input())
    b.sort()
    moji = "".join(b)
    if (moji in d):
        d[moji] += 1
    else:
        d[moji] = 1
x = 0
for i in d:
    if d[i] >=1:
        x += d[i]*(d[i]-1)/2
print(int(x))

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

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

print(ans)

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

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += i*(i-1)//2
    print(round(int(cnt)))


main()

Solution (Python):
import collections
n = int(input())
x = [''.join(sorted(input())) for _ in range(n)]
a = collections.Counter(x)
print(sum(i * ~-i // 2 for i in a.values()))

Solution (Python):

from collections import Counter

N = int(input())
s = []
for i in range(N):
    s1 = "".join(sorted(input()))
    s.append(s1)
    
c = list(Counter(s).values())
ans = 0
for i in c:
    if i >= 2:
        ans += (i * (i - 1)) // 2
print(ans)

Solution (Python):
import collections

N = int(input())
L = list()
for i in range(N):
  L.append("".join(sorted(input())))
  

d = collections.Counter(L)

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

print(ans)

Solution (Python):
n=int(input())
s=[input() for i in range(n)]
dic={}
l=list()
cnt=0
for i in range(n):
  k=sorted(s[i])
  t=''.join(k)
  l.append(t)
  if l[i] in dic:
    dic[l[i]]+=1
  else:
    dic[l[i]]=0
c=list(dic.values())
for i in range(len(c)):
   cnt+=c[i]*(c[i]+1)//2
print(cnt)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(sorted(input()))
a.sort()
p=1
q=0
for i in range(n-1):
  if a[i]==a[i+1]:
    p+=1
  else:
    q+=p*(p-1)//2
    p=1
q+=p*(p-1)//2
print(q)

Solution (Python):
n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = list(input())
  s = ''.join(sorted(s))
  hsh[s] += 1

x = 0
for i in hsh.keys():
  x += (hsh[i]*(hsh[i]-1))//2

print(x)

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

combs = 0
c = collections.Counter(s)




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

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=[input() for _ in range(N)]
    Ss=["".join(sorted(x)) for x in S]
    Ss.sort()

    ans = 0
    cnt = 0
    s0 = Ss[0]
    for s in Ss[1:]:
        if s == s0:
            cnt += 1
        else:
            ans += (cnt+1)*cnt//2
            s0 = s
            cnt = 0
            continue
    ans += (cnt+1)*cnt//2

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

n = int(input())

s = [",".join(sorted(input())) for i in range(n)]

c = collections.Counter(s)

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

print(ans)

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

n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
c = collections.Counter(s)
ans = 0

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

print(ans)

Solution (Python):

import sys
import collections






from scipy.misc import comb 





def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = [''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]
  
    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >= 2:
            count += comb(c, 2, exact=True)

    print(count)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import collections


from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l

from functools import reduce
import operator as op






def nCr(n, r):
    r = min(r, n - r)
    upper = reduce(op.mul, range(n, n-r, -1), 1)
    lower = reduce(op.mul, range(r, 0, -1), 1)
    return upper // lower

def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = [''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]
  
    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >= 2:
            count += nCr(c, 2)
            
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())

dict = {}

for i in range(N):
    s = input()

    temp = [s[j] for j in range(len(s))]
    temp.sort()
    s2 = temp[0]
    for j in range(len(s)):
        if j == 0: continue
        s2 += temp[j]
    if s2 in dict:
        dict[s2] += 1
    else:
        dict[s2] = 1

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

Solution (Python):
import collections

n=int(input())
s = [",".join(sorted(input())) for i in range(n)]

c = collections.Counter(s)

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

print(ans)

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

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

Solution (Python):
n = int(input())
st = {}
sv = {}
for i in range(n):
	tmp = "".join(sorted(input()))
	if tmp in st.keys():
		sv[tmp] += st[tmp]
		st[tmp] += 1
	else:
		st[tmp] = 1
		sv[tmp] = 0


print(sum(sv.values()))

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

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))
ans = 0
n = int(input())
s = [input() for i in range(n)]
anagram = {}
for i in s:
  t = [0] * 26
  for j in i:
    t[ord(j)-ord("a")] += 1
  t = "".join(map(str, t))
  if t in anagram:
    anagram[t] += 1
  else:
    anagram[t] = 1
for i in anagram.values():
  if i >= 2:
    ans += cmb(i, 2)
print(ans)

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

ss = [''.join(sorted(i)) for i in s]
ans = 0
key_dict = {}

for i in ss:
    if i in key_dict:
        key_dict[i] += 1
    else:
        key_dict[i] = 1

a = key_dict.values()
al = [i * (i-1) / 2 if i > 1 else 0 for i in a]

ans = int(sum(al))
print(ans)

Solution (Python):
n = int(input())
str_list = [''] * n
ans = 0

for i in range(n):
  text = list(input())
  text.sort()
  str_list[i] = ''.join(text)

str_list.sort()

current_str = str_list[0]
count = 0

for i in range(1, n):
  if current_str == str_list[i]:
    count += 1
  else:
    if count > 0:
      for j in range(1, count+1):
        ans += j
    count = 0
    current_str = str_list[i]

if count > 0:
  for j in range(1, count+1):
    ans += j
  

print(ans)

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

dic = {}
count = 0

for i in range(n) :
    tmp = str.join('', sorted(list(input())))
    if tmp not in dic :
        dic[tmp] = 0
    else :
        dic[tmp] += 1
        count += dic[tmp]

print(count)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

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

n = inp()
tempcons = 0
ans = 0

Slist = sorted([sorted(input()) for i in range(n)])
for i in range(n-1):
    if Slist[i] == Slist[i+1]:
        tempcons += 1
    else:
        ans += pair(tempcons+1)
        tempcons = 0
ans += pair(tempcons+1)

print(ans)

Solution (Python):
from collections import Counter
def main():
    N = int(input())
    d = Counter()
    for _ in range(N):
        t = ''.join(sorted(input()))
        d[t] += 1
    r = 0
    for v in d.values():
        if v == 1:
            pass
        r += v * (v - 1) // 2
    return r

print(main())

Solution (Python):
import math
n = int(input())
li = list()
for _ in range(n):
    li.append(''.join(sorted(input())))
li.sort()

ans = 0
i = 0
while i < n:
    cnt = 1
    c = li[i]
    while i < n - 1 and li[i] == li[i + 1]:
        cnt += 1
        i += 1
    i += 1
    if cnt > 1:
        ans += math.factorial(cnt) // (math.factorial(cnt - 2) * math.factorial(2))
print(ans)

Solution (Python):


n = int(input())
words = {}
ans = 0

for i in range(n):
  t = ''.join(sorted(input()))
  if t in words:
    ans += words[t]
    words[t] += 1
  else:
    words[t] = 1
    
print(ans)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    d = defaultdict(int)
    for i in range(N):
        s = list(input())
        d["".join(sorted(s))] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
from collections import Counter
def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

n=int(input())

a=["".join(sorted(input().rstrip('\r\n'))) for i in range(n)]
def r(n):
    cnt=0
    for i in range(n):
        cnt+=i+1
    return cnt

my_dic={}
for i in a:
    if i in my_dic:
        my_dic[i]+=1
    else:
        my_dic[i]=1

res=0
for i in my_dic.values():
    res+=r(i-1)
        
print(res)