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):
import math
N=int(input())
S=[input() for i in range(N)]
ans=[]
count = 0
cnt=0
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
"""
def anagram(a,b):
    A=[]
    B=[]
    for i in range(10):
        A.append(a[i])
        B.append(b[i])
    A.sort()
    B.sort()
    if A==B:
        return "Yes" """
for i in range(N):
    kari=[]
    for j in range(10):
        kari.append(S[i][j])
    else:
        kari.sort()
        ans.append(kari)
ans.sort()
kari=[]
for i in range(N-1):
    if ans[i]==ans[i+1]:
        count+=1
    else:
        kari.append(count+1)
        count=0
else:
    kari.append(count+1)

for j in range(len(kari)):
    if kari[j]>=2:
        cnt+=comb(kari[j],2)
print(cnt)

Solution (Python):
N=int(input())
d=dict()
ans=0
for _ in range(N):
  s=input()
  s=tuple(sorted(s))
  if s in d:
    d[s]+=1
  else:
    d[s]=0
for i in d.values():
  ans+=(int(i)**2+int(i))/2
print(int(ans))

Solution (Python):
n=int(input())
l=[list(input()) for _ in range(n)]
dic_l={}
cnt=0
ans_lst=[]
for i in range(n):
  l[i].sort()
  l[i]=str(l[i])
  if l[i] not in dic_l:
    dic_l[l[i]]=1
  else:
    dic_l[l[i]]+=1
for j in dic_l.values():
  if j>=2:
    ans_lst.append(j)
    cnt += int(j*(j-1)/2)
print(cnt)

Solution (Python):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=int(input())
l=[list(input()) for _ in range(n)]
dic_l={}
cnt=0
ans_lst=[]
for i in range(n):
  l[i].sort()
  l[i]=str(l[i])
  if l[i] not in dic_l:
    dic_l[l[i]]=1
  else:
    dic_l[l[i]]+=1
for j in dic_l.values():
  if j>=2:
    ans_lst.append(j)
    cnt += comb(j,2)
print(cnt)

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

Solution (Python):
N = int(input())    
S = [0]*N
for i in range(N):
    t = list(input())
    t.sort()
    t_sort = "".join(t)
    S[i] = t_sort

count = 0
result={}
for i in range (0,len(S)):
    item = S[i]
    if item in result:
        count += result[item]
        result[item] = result[item]+1
    else:
        result[item] = 1
    
print(count)

Solution (Python):
from collections import Counter
N = int(input())
A = [sorted(input()) for _ in range(N)]
a = [''.join(i) for i in A]
c = Counter(a)
cnt = 0
for j in c.values():
    cnt += j*(j-1)//2
print(cnt)

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

Solution (Python):

from collections import defaultdict as dd
N = int(input())
a = [input() for _ in range(N)]
dic=dd(int)
for i,elem in enumerate(a):
    a[i] = tuple(sorted(elem))
    dic[a[i]] += 1
res = sum([val*(val-1)//2 for val in dic.values()])
print(res)

Solution (Python):

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



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

x = set(s)
y = []
for i in range(len(x)):
    y.append(s.count(s[i]))


for j in range(len(y)):
    ans += int((y[j]*(y[j]-1))/2)

print(ans)
"""

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

for _ in range(n):
    s = input()
    s_count = 0
    for c in s:
        s_count += 10**(ord(c)-97)
    s_count_dir[s_count] = s_count_dir.get(s_count,0) + 1

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

Solution (Python):
import sys
from collections import Counter

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

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

main()

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

print(ans)

Solution (Python):
import math
n = int(input())
list_voc = [str(input()) for _ in range(n)]
list_mo = []
for i, s in enumerate(list_voc):
    list_n = list(s)
    list_n.sort()
    list_n = ''.join(list_n)
    list_mo.append(list_n)

ans = {}
for s in list_mo:
    if s in ans:
        ans[s] += 1
    else:
        ans[s] = 1


ans_val = []

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


for s in ans:
    if ans[s] != 1:
        ans_val.append(cmb(ans[s], 2))


print(sum(ans_val))

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
slis = []
for i in range(N) :
    s = list(input())
    s.sort()
    slis.append(s)

slis.sort()
temp = 1
ans = 0

from operator import mul
from functools import reduce

def combinations_count(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

for i in range(1, N) :
    if slis[i] == slis[i-1] :
        temp += 1
    else :
        if temp == 2 :
            ans += 1
        elif temp >= 3 :
            ans += combinations_count(temp, 2)
        temp = 1

if temp == 2 :
    ans += 1
elif temp >= 3 :
    ans += combinations_count(temp, 2)

print(ans)

Solution (Python):
from math import factorial
def comb(n,k):
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)
  b=factorial(k)
  c=factorial(n-k)
  return a//(b*c)
n=int(input())
s=[sorted(list(input())) for i in range(n)]
s.sort()
cnt=1
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=comb(cnt,2)
    cnt=1
if cnt>=2:
  ans+=comb(cnt,2)
print(ans)

Solution (Python):
N = int(input())
dic = {}
for _ in range(N):
    IN = input()
    A = "".join(sorted(list(IN)))
    if A not in dic:
        dic[A] = 1
    else:
        dic[A] += 1
answer = 0
for k,v in dic.items():
    answer += v*(v-1)//2
print(answer)

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

Solution (Python):
import sys
import os


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

    N = int(sys.stdin.readline().rstrip())
    lines = ["".join(sorted(line.rstrip())) for line in sys.stdin.readlines()]

    ret = 0
    sortedlines = {}
    for n in range(N):
        item = lines[n]
        if item in sortedlines:
            sortedlines[item] += 1
            ret += sortedlines[item]
        else:
            sortedlines[item] = 0

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import os


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

    N = int(sys.stdin.readline().rstrip())
    lines = ["".join(sorted(line.rstrip())) for line in sys.stdin.readlines()]

    ret = 0
    sortedlines = {}
    for n in range(N):
        item = lines[n]
        if item in sortedlines:
            sortedlines[item] += 1
            ret += sortedlines[item] - 1
        else:
            sortedlines[item] = 1

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

n = int(input())
dic = defaultdict(int)
cnt = 0
for i in range(n):
    s = sorted(input())
    cnt += dic[''.join(s)]
    dic[''.join(s)] += 1
    
print(cnt)

Solution (Python):
import collections

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]

c = collections.Counter(s)

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

print(ans)

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

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

ans = 0
for i in d.values():
    ans += tousa(i)
print(ans)

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

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


n = int(input())

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


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


print(answer)

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

table = {}
ans = 0
for i in S:
    s = ''.join(sorted(i))
    if s not in table:
        table[s] = 0
    else:
        table[s] += 1
        ans += table[s]
print(ans)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
d={} ; a=[]
from collections import Counter
for _ in range(int(input())):
    s=input()
    a.append(tuple(sorted(s)))
d=Counter(a)
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2
print(ans)

Solution (Python):


from collections import defaultdict


def main():
    N = int(input())
    dct = defaultdict(int)

    for i in range(N):
        s = input()
        sorted_s = "".join(sorted(s))
        dct[sorted_s] += 1

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ss = {}
for _ in range(n):
  s = input()
  S = []
  for c in s:
    S.append(c)
  S.sort()
  s = ''.join(S)
  if s in ss:
    ss[s] += 1
  else:
    ss[s] = 1

def func(n):
  if n ==1:
    return 0
  return n*(n-1)//2
    
ans = 0
for key in ss:
  ans += func(ss[key])
    
    
    
print(ans)

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

Solution (Python):
N = int(input())
a = []
for i in range(N):
    S = list(input())
    S.sort()
    a.append("".join(map(str,S)))
a.sort()
a.append("z")

c = []
r = 1
for i in range(1,N+1):
    if a[i] == a[i-1]:
        r += 1
    else:
        if r > 1:
            c.append(r)
        r = 1

ans = 0
if len(c) > 0:
    for i in range(len(c)):
        ans += c[i] * (c[i] - 1) // 2
print(ans)

Solution (Python):

N = int(input())
ans = 0
d = {}
for i in range(N):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1

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

Solution (Python):
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sotmp=sorted(tmp)
    stmp=''.join(sotmp)
    s.append(stmp)

ss=sorted(s)

for word in ss:
    if((word in cnt.keys())==False):
        cnt[word]=0
    else:
        cnt[word]+=1


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

print(total)

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

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

Solution (Python):


def main():
    n = int(input())
    ss = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s not in ss.keys():
            ss[s] = 0
        ss[s] = ss[s] + 1

    print(sum(c2(v) for k, v in ss.items()))

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

if __name__ == "__main__":
    main()

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

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):
N = int(input())
S = [0]*N
dict = {}
cnt = 0
for i in range(N):
    S[i] = sorted(input())
    if tuple(S[i]) in dict:
        dict[tuple(S[i])] += 1
        cnt += dict[tuple(S[i])]    
    dict.setdefault(tuple(S[i]),0)
print(cnt)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(list(input()))))
S.sort()
output = 0

t = 1
n=1
while t<N:
    if S[t-1]==S[t]:
        n+=1
    else:
        output += int(n*(n-1)*0.5)
        n=1
    t+=1
output += int(n*(n-1)*0.5)
print(output)

Solution (Python):



from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()

    dic = Counter()
    ans = 0
    for i in range(n):
        s = input()
        ss = "".join(sorted(s))
        dic[ss] += 1
        ans += dic[ss]-1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict


n, *s = sys.stdin.read().split()
d = defaultdict(int)
ans = 0
for si in s:
    d[''.join(sorted(si))] += 1
for x in d.values():
    ans += x * (x - 1) // 2
print(ans)

Solution (Python):
import sys
from collections import defaultdict


n, *s = sys.stdin.read().split()
d = defaultdict(int)
ans = 0
for si in s:
    d[''.join(sorted(si))] += 1
for x in d.values():
    ans += x * (x - 1) // 2
print(ans)

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

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

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

n = int(input())
s = []
for _ in range(n):
    s.append(input())

t = [''.join(sorted(str)) for str in s]
c = Counter(t)
ll = [i for _, i in c.items() if i > 1]
cnt = 0
for i in ll:
    cnt += count_combinations(i, 2)

print(cnt)

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

S=[""]*N
T={}
count=0

for i in range(N):
    S[i]=sorted(s[i])
    S[i]="".join(S[i])
    if S[i] not in T:
        T[S[i]]=1
    else:
        count+=T[S[i]]
        T[S[i]]+=1

print(count)

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

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

Solution (Python):
N = int(input())
d = {}
for _ 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 k, v in d.items():
    ans += v * (v - 1) // 2

print(ans)

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

Solution (Python):
import collections

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

c = collections.Counter(s)

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

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = ["".join(sorted(str(readline().rstrip().decode('utf-8')))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for k, v in s:
        if v > 1:
            t += (1 + v - 1) * (v - 1) // 2
    print(t)


if __name__ == '__main__':
    solve()

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

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

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

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

d={}
for i in l:
  i=''.join(i)
  if i in d:
    d[i]+=1
  else:
    d[i]=1

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

Solution (Python):
n = int(input())
d = dict()
res = 0
for _ in range(n):
    s = input()
    s = list(s)
    s.sort()
    s = "".join(s)
    if s in d:
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(res)

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

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

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

Solution (Python):
N = int(input())
words = []
for i in range(N):
  s_in = str(input())
  
  s_sort = ''.join(sorted([ch for ch in s_in]))
  words.append(s_sort)



from collections import Counter
cntr = Counter(words)





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

print(ans)

Solution (Python):
N = int(input())
words = []
for i in range(N):
  s_in = str(input())
  s_sort = ''.join(sorted([ch for ch in s_in]))
  words.append(s_sort)



from collections import Counter
cntr = Counter(words)



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

print(ans)

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

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

print(ans)

Solution (Python):
from collections import defaultdict
from scipy.misc import comb

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

dd = defaultdict(int)
for i in range(N):
  s = "".join(sorted(S[i]))
  dd[s] += 1

ans = 0
for key, val in dd.items():
  ans += comb(val, 2, exact=True)

print(ans)

Solution (Python):
from collections import Counter
from collections import defaultdict
from scipy.misc import comb

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

dd = defaultdict(int)
for i in range(N):
  s = "".join(sorted(S[i]))
  dd[s] += 1

ans = 0
for key, val in dd.items():
  ans += comb(val, 2, exact=True)

print(int(ans))

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

Solution (Python):
from collections import defaultdict
n = int(input())
dic = defaultdict(int)
ans = 0
for i in range(n):
    x = sorted(list(input()))
    s = "".join(x)
    dic[s] += 1

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

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

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

Solution (Python):
n=int(input())
s=[]
ans=0
count=1
def comb(n,k):
  for i in range(k-1):
    n*=n-i-1
    k*=k-i-1
  return n//k

for i in range(n):
  a=list(input())
  a.sort()
  " ".join(a)
  s.append(" ".join(a))
s.sort()
for i in range(n-1):
  if s[i]==s[i+1]:
    count+=1
  else:
    ans+=(comb(count,2))
    count=1
if count>0:
  ans+=(comb(count,2))
print(ans)

Solution (Python):
import math
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
l.sort()
c = 0
b = l[0]
ans = 0
for s in l[1:]:
    if s == b:
        c += 1
    else:
        ans += c * (c + 1) * 0.5
        c = 0
        b = s
ans += c * (c + 1) * 0.5
print(int(ans))

Solution (Python):
import math
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
l.sort()
c = 0
b = l[0]
ans = 0
for s in l[1:]:
    if s == b:
        c += 1
    else:
        ans += c * (c + 1) * 0.5
        c = 0
    b = s
ans += c * (c + 1) * 0.5
print(int(ans))

Solution (Python):
n = int(input())
d = [0 for i in range(n)]
for i in range(n):
    a = 0
    for j in input():
        a += 10**(ord(j)-97)
    d[i] = a
d = sorted(d)
ans = 0
co = 1
for i in range(1, n):
    if d[i-1] == d[i]:
        co += 1
    else:
        ans += co*(co-1) // 2
        co = 1
ans += co*(co-1) // 2
print(ans)

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

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

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

from collections import Counter

c = Counter(s)
keys, values = zip(*c.most_common())


ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += n*(n-1)//2
        
print(ans)

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

N = int(input())
S = defaultdict(int)

for i in range(N):
    s = sorted(input())
    S[''.join(s)] += 1

ans = 0
for v in S.values():
    if v > 1:
        pairs = factorial(v) // (2 * factorial(v-2))
        ans += pairs

print(ans)

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

ab.sort()
count = 1
memo = []
for i in range(n-1):
    
    if ab[i] == ab[i+1]:
        count += 1
    else:
        memo.append(count)
        count = 1
    if i == n-2:
        memo.append(count)
ans = 0
for i in memo:
    ans += i*(i-1)//2
print(ans)

Solution (Python):
import collections

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

c = 0
r = collections.Counter(s)
for v in r.values():
    c += (v * (v - 1)) // 2

print(c)

Solution (Python):
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

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

count=[1]*len(t)
j=0
for i in range(1,n):
  if t[j]==s[i]:
    count[j]+=1
  else:
    j+=1

ans=0
for i in range(len(t)):
  ans+=((count[i])*(count[i]-1))//2
  
print(ans)

Solution (Python):

from collections import Counter
n = int(input())
lst = [input() for i in range(n)]
cnt = Counter()
ans = 0
for i in lst:
    a = ''.join(sorted(list(i)))
    if a in cnt:
        ans += cnt[a]
    cnt[a] += 1

print(ans)

Solution (Python):
import collections

n = int(input())
s = [None] * n

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

ctr = collections.Counter(s)

count = 0

for i in ctr.values():
    count += int(i*(i-1)/2)

print(count)

Solution (Python):
import sys
from collections import Counter
import numpy as np

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

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

def main():
    t = [''.join(sorted(t)) for t in s]
    v = np.array(list(Counter(t).values()), dtype=np.int64)
    return np.sum(comb_2(v))

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys
from collections import Counter

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

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

def main():
    t = [''.join(sorted(t)) for t in s]

    c = Counter(t)
    pairs_cnt = 0
    for v in c.values():
        pairs_cnt += comb_2(v)
    
    return pairs_cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

d=dict()

for i in range(n):
    if s[i] not in d.keys():
        d[s[i]]=1
    else:
        d[s[i]]+=1
ans=0
for v in d.values():
    ans+=v*(v-1)/2
print(int(ans))

Solution (Python):
from collections import Counter

n=int(input())
s=[]
for i in range(n):
    x=input()
    y=[]
    for i in x:
        y.append(i)
    y.sort()
    s.append(''.join(y))

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

Solution (Python):
import numpy as np

def Speed_Anag_Count(String):
    count = {}
    for i in String:
        i = sorted(i)
        i = str(''.join(i))
        if count.get(i) is None:
            count[i] = 0
        count[i] += 1
    
    return count

N = int(input())

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

count = Speed_Anag_Count(S)

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

Solution (Python):



n = int(input())
sort = [""]*n
for i in range(n):
    s = list(input())
    s.sort()
    sort[i] = s
sort.sort()

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

Solution (Python):
m = {}
ans = 0
n = int(input())
def C(x:int) -> 'conbination_nC2':
	return x*(x-1)/2

for i in range(n):
	s = input()
	new_str = ''.join(sorted(s))
	if new_str in m.keys() :
		m[new_str] += 1
	else :
		m[new_str] = int(1)
	

for i in m:
	ans += C(m[i])

print(int(ans))

Solution (Python):
import collections

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

lis=[list(s[i]) for i in range(n)]
lis_sort = [sorted(lis[i]) for i in range(n)]
lis_sort = [''.join(lis_sort[i]) for i in range(n)]
lis_sort.sort()

c = collections.Counter(lis_sort)
values, counts = zip(*c.most_common(len(c)))
cnt=0
for i in range(len(counts)):
    if counts[i]==2: cnt+=1
    elif counts[i]>2: cnt+=counts[i]*(counts[i]-1)//2
print(cnt)

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

S = [["" for i in range(10)] for j in range(N)]
for i in range(N):
    tmp = list(input())
    tmp_s = sorted(tmp)
    S[i] = tmp_s
S_s = sorted(S)
res = 0
i = 0
while i<N:
    j = 1
    count = 1
    while i+j<N and S_s[i] == S_s[i+j]:
        j = j + 1
        count = count + 1

    if count > 1:
        res += count*(count-1)//2
    else:
        res += 0
    i = i + j

print(res)

Solution (Python):
N = int(input())
s = [0]*N
d = {}

for i in range(N):
    s_lst = sorted(input())
    s[i] = ''.join(s_lst)
    if d.get(s[i]) is None:
        d[s[i]] = 1
    else:
        d[s[i]] += 1

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

print(int(ans))

Solution (Python):
def nc2(x):
    return 0 if x == 1 else x * (x - 1) // 2


N = int(input())
S = {}
for i in range(N):
    w = ''.join(sorted(input()))
    S[w] = S.get(w, 0) + 1
ans = sum(map(nc2, S.values()))
print(ans)

Solution (Python):
import collections
N=int(input())
slist=[''.join(sorted(input())) for i in range(N)]
c=collections.Counter(slist)
ans=0
for i,j in c.most_common():
    ans+=j*(j-1)//2
print(ans)

Solution (Python):
import collections
N=int(input())
tmp=[sorted(input()) for i in range(N)]
slist=[''.join(tmp[i]) for i in range(N)]
c=collections.Counter(slist)
ans=0
for i in c.most_common():
    ans+=i[1]*(i[1]-1)//2
print(ans)

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

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

s = ["".join(sorted(i)) for i in s]
table = {}

count = 0
for word in s:
  if word in table:
    count += table[word]
    table[word] += 1
  else :
    table[word] = 1
print(count)

Solution (Python):
N = int(input())
s = [list(input()) for i in range(N)]
for i in range(N):
    s[i].sort()
s = [''.join(s[i]) for i in range(N)]

import collections
cnt = collections.Counter(s)

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

print(ans)

Solution (Python):
n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))

anagram_lst.sort()
count = 1
for i in range(n-1):
    anagram1 = anagram_lst[i]
    anagram2 = anagram_lst[i+1]
    if anagram1==anagram2:
        count +=1
        if i==n-2:
            number += addition(count-1)
    else:
        number += addition(count-1)
        count = 1

print(number)