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, collections

def combinations_count(n):
  d = 2
  if n < d:
    return 0
  return math.factorial(n) // (math.factorial(n - d) * math.factorial(d))
      

rows = int(input()) 
str_list = [input() for i in range(rows)]
sorted_str_list = map(lambda s: ''.join(sorted(s)), str_list)
  
counter = collections.Counter(sorted_str_list)
ans = sum(map(lambda v: combinations_count(v), counter.values()))
print(ans)

Solution (Python):
from scipy.misc import comb
n=int(input())
d={}
cnt=0
for i in range(n):
  a=[i for i in input()]
  a.sort()
  b="".join(a)
  d[b]= d[b]+1 if b in d else 1
for k,v in d.items():
  cnt+=comb(v,2,exact=True)
print(cnt)

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

d = {}
ans = 0

for s in l:
  if s in d:
    d[s] += 1
    ans += d[s]-1
  else:
    d[s] = 1

print(ans)

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

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

Solution (Python):
from collections import defaultdict
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
memos = defaultdict(lambda : 0)
for key in dic.keys():
    value = dic[key]
    if not value in memos.keys():
        x = value*(value-1)/2
        memos[value] = int(x)
    else:
        x = memos[value]
    count += x
print(int(count))

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

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

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = "".join(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)

Solution (Python):
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
d = {}
for i in range(n):
  sortsi = ''.join(sorted(s[i]))
  if sortsi in d:
    cnt+=d[sortsi]
    d[sortsi]+=1
  else: 
    d[sortsi]=1
print(cnt)

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

l = []

for x in s:
  l.append(tuple(sorted(x)))

import collections
ans = 0
for _, c in collections.Counter(l).most_common():
  if c >= 1:
    ans += c * (c - 1) // 2

print(ans)

Solution (Python):
def conb(a, b):
    nume = 1
    deno = 1
    for i in range(b):
        nume *= a - i
        deno *= i + 1

    return int(nume / deno)


n = int(input())

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

sum = 0
for k in cnt_dict:
    v = cnt_dict[k]
    if v > 1:
        sum += conb(v, 2)

print(sum)

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

s=[]

d={}

ans=0

for i in range(n):
    tmp="".join(sorted(input()))
    if tmp not in d:
        d[tmp]=1
    else:
        d[tmp]+=1

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

print(ans)

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


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


ans = 0
for i in s.values():
    ans += calc(i)
print(ans)

Solution (Python):
import string
import collections

N = int(input())
count = 0

s = []

for i in range(0,N):
  s.append(''.join(sorted(input())))

  
c = collections.Counter(s)
go = c.most_common()

for i in range(len(go)):
  k = go[i][1]
  count+=k*(k-1)//2
  
print(count)

Solution (Python):
n = int(input())
words = set()
from collections import defaultdict
count_dict = defaultdict(int)
ans = 0

for i in range(n):
  word = str(sorted(input()))
  if word in words:
    count_dict[word] += 1
    ans += count_dict[word]
  else:
    words.add(word)
    
print(ans)

Solution (Python):
n = int(input())
st = dict()
cnt = 0
for i in range(n):
    stx="".join(sorted(list(input())))
    if stx not in st:
        st[stx] = 0
    else:
        st[stx] +=1
        cnt += st[stx]
print(cnt)

Solution (Python):
from collections import defaultdict

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 a, b in dct.items():
    ans += b *(b-1)//2

print(ans)

Solution (Python):
n = int(input())
D = {}
count = 0
for i in range(n):
    line = "".join(sorted(list(input())))
    if line not in D:
        D[line] = 0
    else:
        D[line] += 1
        count += D[line]

print(count)

Solution (Python):
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
snm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
l=[]
d=defaultdict(int)
for i in range(n):
    s=list(si())
    s.sort()
    tmp=''
    for ss in s:
        tmp+=ss
    l.append(tmp)

for ll in l:
    d[ll]+=1

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

print(ans)

Solution (Python):
n=int(input())
slist=[]
for i in range(n):
    s10=input()
    si=[]
    for ii in range(10):
        si.append(s10[ii])
    si.sort()
    stmp=""
    for ii in range(10):
        stmp=stmp+si[ii]
    slist.append(stmp)
slist.sort()
    
icnt=0   
i=0 
while i<=n-2:
    j=i+1
    jcnt=0
    while slist[i]==slist[j]:
        jcnt=jcnt+1
        icnt=icnt+jcnt
        j=j+1
        if j>=n:
            break
    i=j
    if i>=n-1:
        break
            
print(icnt)

Solution (Python):
from math import factorial


def combination2(num: int) -> int:
    return int(factorial(num) / (2 * factorial(num - 2)))


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

dictionary = {}

for s in ss:
    sorted_string = "".join(sorted(s))
    count = dictionary.get(sorted_string)
    if count is None:
        dictionary[sorted_string] = 1
    else:
        dictionary[sorted_string] = count + 1

counter = 0

for count in dictionary.values():
    if count > 1:
        counter += combination2(count)

print(counter)

Solution (Python):
from collections import Counter

N = int(input())
s = []
for i in range(N):
  s += [''.join(sorted(input()))]
cnt = sum([x*(x - 1) // 2 for x in Counter(s).values()])
print(int(cnt+0.5))

Solution (Python):
N = int(input())
d = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)

Solution (Python):
from collections import defaultdict

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

answer = 0
counter = defaultdict(int)

for s in S:
  tmp = 0
  ss = list(s)
  ss.sort()
  for i in range(10):
    tmp += (ord(ss[i]) - ord("a")) * 26 ** i
  answer += counter[tmp]
  counter[tmp] += 1
  
print(answer)

Solution (Python):
from scipy.misc import comb
n = int(input())
dic = {}
for _ in range(n):
  s = input()
  tmp = [0]*26
  for i in s:
    tmp[ord(i)-97] += 1
  tmp = tuple(tmp)
  if tmp in dic:
    dic[tmp] += 1
  else:
    dic[tmp] = 1
total = 0
for i in dic.values():
  if i<2:
    continue
  total += comb(i, 2, exact=True)
print(total)

Solution (Python):
from collections import Counter
n=int(input())
slis=[]
for i in range(n):
	s=sorted(list(input()))
	slis.append(s)
ctr=Counter()
ans=0
for s in slis:
	a="".join(s)
	if a in ctr:
		ans+=ctr[a]
	ctr[a] +=1
print(ans)

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

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

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1
 
ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Solution (Python):


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

dic = {}
for i in range(n):
    tmp = sorted(list(s[i]))
    tmp2 = "".join(tmp)
    if dic.get(tmp2) == None:
        dic[tmp2] = 1
    else:
        dic[tmp2] += 1


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

print(ans)

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

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i].rstrip())))
    d[s] += 1

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

Solution (Python):
import string
import collections

n = int(input())
ans=[]
for i in range(n):
  s=input()
  c = collections.Counter(s)
  ans.append("".join(map(str,[c[i] for i in string.ascii_lowercase])))

c2 = collections.Counter(ans)
cnt=0
for k, v in c2.items():
  cnt+=(v-1)*v//2

print(cnt)

Solution (Python):
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.values():
        if i < 2:
            continue
        else:
            res += i * (i-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import itertools

n = int(input())
x = []
for i in range(n):
  x.append(sorted(input()))
  
x_sort = sorted(x)
ans = 0

counter = Counter(map(tuple, x_sort))
for word, cnt in counter.most_common():
  ans += (cnt*(cnt-1))//2
  
print(ans)

Solution (Python):
from collections import Counter


def solve(s):
    c = Counter(s)

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

    return ans


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

for i in range(n):
    tmp = sorted(input())
    s.append("".join(tmp))

print(solve(s))

Solution (Python):
from scipy.misc import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()

mp={}

for i in range(N):
    key = "".join(sorted(input()))
    if key in mp:
        mp[key] += 1
    else:
        mp[key] = 1

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

print(res)

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()

mp={}

for i in range(N):
    key = "".join(sorted(input()))
    if key in mp:
        mp[key] += 1
    else:
        mp[key] = 1

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

print(res)

Solution (Python):
from collections import Counter

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

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

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

l = {}
for n in range(N):
    if s[n] in l:
        l[s[n]] += 1
    else :
        l[s[n]] = 1

print(sum(l[k] * (l[k]-1) // 2 for k in l))

Solution (Python):

import collections as cl
n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]
sum=0
for i in cl.Counter(a).values():
  sum+=i*(i-1)//2
print(sum)

Solution (Python):

import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1



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

Solution (Python):

import collections as col
n=int(input())
a=[input() for i in range(n)]
b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1

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

Solution (Python):

from collections import defaultdict
n=int(input())
a=[input() for _ in range(n)]
b=defaultdict(int)
for i in a:
  k=''.join(sorted(i))
  b[k]+=1

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

Solution (Python):
N = int(input())
cntS = {}
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in cntS:
    cntS[s] += 1
  else:
    cntS[s] = 1

print(sum([cntS[key]*(cntS[key]-1)//2 for  key in cntS]))

Solution (Python):
import collections
N=int(input())
Slst=["".join(sorted(list(input()))) for i in range(N)]
dic={}
namelst=set()

for S in Slst:
    if S in namelst:
        dic[S]+=1
    else:
        namelst.add(S)
        dic.update({S:1})


print(sum([dic[i]*(dic[i]-1)//2 for i in dic if dic[i]>=2]))

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

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

print(ans)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
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

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

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(sys.stdin.readline().rstrip()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Solution (Python):
import sys
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

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

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(input()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Solution (Python):
import collections

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

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

p=101
ha=[0]*N
for i in range(N):
    for j in range(len(s[i])):
        ha[i]+=pow(p,(ord(s[i][j])-ord("a")))
c=collections.Counter(ha)

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

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

ans = 0
i = 0
while i < n-1:
    if i < n-1 and ss[i] == ss[i+1]:
        count = 2
        if i < n-2 and ss[i+1] == ss[i+2]:
            i+=1
            while i < n-1 and ss[i] == ss[i+1]:
                count+=1
                i+=1
            i-=1
        ans+=(count*(count-1)//2)
    i+=1
print(ans)

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

dic = {}
ans = 0

for i in S:
    tmp = "".join(sorted(i))
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
    
for i in dic.values():
    
    ans += (i*(i-1))//2

print(ans)

Solution (Python):

n = int(input())
s = [str(input()) for _ in range(n)]
sep = ''
dic = dict()
for string in s:
  tmp = sep.join(sorted(string))
  if tmp in dic:
    dic[tmp] += 1 
  else :
    dic[tmp] = 1
ans = 0
for i in dic.values(): 
  ans += i*(i-1)//2
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = collections.Counter(["".join(sorted([c for c in S()])) for _ in range(n)])
    r = 0
    for i in a.values():
        r += i * (i-1) // 2

    return r


print(main())

Solution (Python):
from collections import Counter
n = int(input())
a = [""]*n
for i in range(n):
    a[i] = ''.join(sorted(input()))
b = list(Counter(a).values())
print(sum(int((i-1)*i/2) for i in b))

Solution (Python):
import collections as cl

N = int(input())
a = [""]*N
for i in range(N):
    a[i] = "".join(sorted(list(input())))

b = list(cl.Counter(a).values())

ans = 0
for x in b:
    tmp = x * (x-1) // 2
    ans += tmp
print(ans)

Solution (Python):
import collections as cl

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

Solution (Python):
import collections
n=int(input())
lst=["i"]*n
for i in range(n):
    a=input()
    lst[i]="".join(sorted(a))
count=collections.Counter(lst)
ans=0

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    b=input()
    b=sorted(b)
    b=' '.join(b)
    b=b.replace(" ","")
    a.append(b)
import collections
c=collections.Counter(a)
c=list(c.values())
ans=0
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in c:
    if i>=2:
        ans+=combinations_count(i,2)
print(ans)

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

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

Solution (Python):
T = int(input())
dct ={}
for z in range(T):
    s = "".join(sorted(input()))
    if s in dct:
        dct[s] += 1
    else:
        dct[s] = 1
v = 0
for elem in dct.values():
    v += (elem*(elem-1))//2
print(v)

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

Solution (Python):
def main():
    N = int(input())
    s = "".join(sorted(input()))
    dic = {s:1}
    ans = 0
    for _ in range(N-1):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for i in dic.values():
        ans += (i*(i-1))//2
    return ans

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

Solution (Python):
N = int(input())
D = {}
for i in range(N):
  S = input()
  L = [S[j] for j in range(10)]
  L.sort()
  s = ""
  for j in range(10):
    s = s[:] + L[j]
  if s in D:
    D[s] += 1
  else:
    D[s] = 1
p = 0
for i in D:
  p += (D[i]*(D[i]-1))//2
print(p)

Solution (Python):
from collections import Counter
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

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

count_by_kw=Counter()

for i in s:
    count_by_kw[''.join(sorted(i))]+=1

values, counts = zip(*count_by_kw.most_common())
cnt=0
for i in counts:
    if i>1:
        cnt+=combinations_count(i,2)

print(cnt)

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

for _ in range(n):
    s = "".join(sorted([x for x in input()]))
    d[s] = d.get(s, 0) + 1

ans = 0

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

print(ans)

Solution (Python):
import math

n = int(input())
d = dict()

for _ in range(n):
    s = "".join(sorted([x for x in input()]))
    d[s] = d.get(s, 0) + 1

ans = 0

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

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

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

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

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

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

print(int(ans))

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

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

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

print(int(ans))

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

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

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

print(int(summ))

Solution (Python):


import math
import sys
import heapq
import fractions


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

N = int(input())
s = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0


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

for i in range(1,N):

    if s[i]==s[i-1]:
        n += 1
        if i == N-1:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

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

from math import factorial
from operator import mul
from functools import reduce

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

def main():
    dic = {}
    ans = 0
    for i in range(N):
        S[i].sort()
        tmp = "".join(S[i])
        S[i] = tmp

    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for val in dic.values():
        if val > 1:
            ans += comb(val,2)

    print(int(ans))
    return

if __name__ == "__main__":
    main()

Solution (Python):
import math
import collections


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


n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
counter = collections.Counter(s)
print(sum([combinations_count(i, 2) for i in counter.values() if i > 1]))

Solution (Python):
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
ans = 0
s_dic = {i:0 for i in s}

for j in range(n):
	if s[j] in s_dic :
		s_dic[s[j]] += 1

print(sum(s_dic[k] * (s_dic[k] - 1) // 2 for k in s_dic))

Solution (Python):
N=int(input())
S=sorted(["".join(sorted(input())) for i in range(N)])
D={s:0 for s in S}
for s in S:
  D[s]+=1
print(sum([D[d]*(D[d]-1)//2 for d in D]))

Solution (Python):
from collections import Counter


cnt = Counter()
N = int(input())

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

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

print(ans)

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

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

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

print(ans)

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

for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in dic.keys():
        dic[spell] += 1
    else:
        dic[spell] = 1

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += cnt * (cnt-1) // 2
print(ans)

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

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

C = []
c = 1
for i in range(n - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        C.append(c)
        c = 1
C.append(c)

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a=[]
for i in range(N):
    s=input()
    s="".join(sorted(s)).split()
    a.append(s[0])
num=Counter(a).values()

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

Solution (Python):
from collections import Counter

N = int(input())
a=[]
for i in range(N):
    s=input()
    S=[]
    for j in range(10):
        S.append(s[j])
    S.sort()
    s="".join(S).split()
    a.append(s[0])
x=Counter(a)
num=x.values()

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

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

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

ans = sum(x * (x-1) // 2 for x in c.values())
print(ans)

Solution (Python):
import itertools

n = int(input())
s = []
textSet = set()
ans = 0

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

s.sort()


cnt = 0

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

if cnt > 0:
    
    ans += (cnt + 1) * cnt // 2

print(ans)

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
import numpy as np
n=int(input())
s=list(input() for _ in range(n))

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

ans=0
cnt=1
for i in range(1,n):
    if s[i]==s[i-1]:
        cnt+=1
    elif (s[i]!=s[i-1]) & (cnt>1):
        ans+=combinations_count(cnt, 2) 
        cnt=1
    else:
        continue
if cnt>1:
    ans+=combinations_count(cnt, 2)
print(ans)

Solution (Python):
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
dic = {}
count=0
for i in range(N):
    if s[i] in dic:
        dic[s[i]] = dic[s[i]] + 1
    else:
        dic.setdefault(s[i], 1)
for i in dic.values():
    if i > 1:
        count += i* (i - 1) // 2
print(count)

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

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

print(ans)

Solution (Python):
N=int(input())
s=[''.join(sorted(list(input()))) for i in range(N)]
s.sort()
i=0
out=0
while i<N:
  c=1
  while i+c<N and s[i]==s[i+c]:
    c+=1
    
  out+=c*(c-1)//2
  i+=c
  
print(out)

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

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)

Solution (Python):





from collections import Counter

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

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

Solution (Python):
import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = ''.join(sorted(list(k)))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)