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

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

Solution (Python):
N = int(input())
S = []

dic = dict()

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

for key, val in dic.items():
	if val > 1:
		ans += (val * (val - 1)) / 2
		
print(int(ans))

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

Solution (Python):
n = int(input())
count = {}
res = 0
for i in range(n):
  si = input()
  sortedSi = sorted(si)
  tSi = tuple(sortedSi)
  if tSi not in count:
    count[tSi] = 0
  res += count[tSi]
  count[tSi] += 1
print(res)

Solution (Python):
from math import factorial

N = int(input())
strings = {}
for _ in range(N):
    string = str(sorted(list(input().rstrip('\n'))))
    if string in strings:
        strings[string] += 1
    else:
        strings[string] = 1

count = 0
for value in strings.values():
    if value >= 2:
        count += factorial(value) // 2 // factorial(value - 2)

print(count)

Solution (Python):
N = int(input())
S = []
for i in range(N):
  s = list(input())
  s.sort()
  S.append(s)
S.sort()
ans = 0
snt = 1
for i in range(N-1):
  if S[i]==S[i+1]:
    snt += 1
  else :
    ans += (snt*(snt-1))//2 if snt>1 else 0
    snt = 1
ans += (snt*(snt-1))//2 if snt>1 else 0
print(ans)

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

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

dic = dict()
for i in range(N):
    S = input()
    new = ''.join(sorted(S))
    
    if not new in dic:
        dic[new] = 0
        
    dic[new] += 1

ans = 0

for key,val in dic.items():
    if val > 1:
        ans += (val*(val-1)) // 2

print(ans)

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

Solution (Python):
a=int(input())
lis=sorted([sorted([f for f in input()]) for i in range(a)])
lis+=["w"]
kari=""
ans=0
cou=1
for i in lis:
  if kari!=i:
    ans+=cou*(cou-1)/2
    cou=1
    kari=i
  else:
    cou+=1
print(int(ans))

Solution (Python):
from collections import Counter

count = Counter()
for i in range(int(input())):
	s = sorted(input())
	count[''.join(s)] += 1
	
ans = 0

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

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

ans = 0
A = {}

for i in range(0, N):
    S[i] = sorted(S[i])
    S[i] = ''.join(S[i]) 
    if S[i] in A.keys():
        ans += A[S[i]]
        A[S[i]] += 1
    else:
        A[S[i]] = 1
    
print(ans)

Solution (Python):
import collections

n = int(input())
ss = ["".join(sorted(input())) for _ in range(n)]
counter = collections.Counter(ss)
count = 0
for k, v in counter.items():
    count += v * (v - 1) // 2
print(count)

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

Dict = {} 
ans = 0

for i in range(N):
    s[i] = ''.join(sorted(s[i])) 
    if s[i] in Dict:
        ans += Dict[s[i]] 
        Dict[s[i]] += 1 
    else:
        Dict[s[i]] = 1 

print(ans)

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

d = defaultdict(int)
for s in S:
    d[''.join(sorted(s))] += 1
    
ans = 0
for v in d.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

Solution (Python):
N = int(input())
s = []
l = 1
z = 0
s = [input() for _ in range(N)]
for i in range(0,N):
    s[i] = ''.join(sorted(s[i]))
s.sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        l += 1
    else:
        z += l*(l-1)/2
        l = 1
z += l*(l-1)/2
print(int(z))

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

Solution (Python):
N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
count = 0

B = sorted(A)
A_unique_count = 1

for i in range(N-1):
  if B[i] == B[i+1]:
    A_unique_count += 1
  else:
    count += A_unique_count * (A_unique_count -1) /2


    A_unique_count = 1

count += A_unique_count * (A_unique_count -1) /2
print(int(count))

Solution (Python):

n = int(input())
can = []
for _ in range(n):
  raw = input()
  made = []
  for k in range(10):
    made.append(raw[k])
  made.sort()
  can.append(made)
can.sort()
ans = 0
combo = 0
for i in range(1,n):
  if can[i] == can[i-1]:
    combo += 1
  else:
    combo = 0
  ans += combo
print(ans)

Solution (Python):
n = int(input())
arr = [input() for _ in range(n)]
ans_dict = {}

for s in arr:
    samp = sorted(s)
    tmp = ""
    for i in samp:
        tmp = tmp + i
    if tmp in ans_dict:
        ans_dict[tmp] += 1
    else:
        ans_dict[tmp] = 1

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

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
ss = [''.join(sorted(s_tmp)) for s_tmp in s]
ss.sort()
count = 1
ans = 0
for i in range(n-1):
    if ss[i] == ss[i+1]:
        count += 1
    else:
        ans += int((count*(count-1))/2)
        count = 1
ans += int((count*(count-1))/2)
print(ans)

Solution (Python):
n = int(input())
arr = [input() for _ in range(n)]
dict = {}
alpha = "abcdefghijklmnopqrstuvwxyz"

for s in arr:
    count = [0]*26
    for i in range(10):
        for j in range(26):
            if s[i] == alpha[j]:
                count[j] += 1
                break
    count = tuple(count)
    if count not in dict:
        dict[count] = 1
    else:
        dict[count] += 1
ans = 0
for val in dict.values():
    ans += val * ( val - 1 ) / 2
print(int(ans))

Solution (Python):
import collections
def resolve():
    N = int(input())
    S = [input() for i in range(N)]
    ans = 0

    for i in range(N):
        S[i]=str(sorted(S[i]))
    c = collections.Counter(S)
    for i in c.values():
        for j in range(1,i):
            ans += j
    print(ans)
    
resolve()

Solution (Python):
N=int(input())
s=[]
for i in range(N):
  ss=list(input())
  ss.sort()
  s.append(ss)
s.sort()
res=0

temp=1
for i in range(N-1):
  if s[i]==s[i+1]:
    temp+=1
    if i==N-2:
      res+=temp*(temp-1)//2
  else:
    res+=temp*(temp-1)//2
    temp=1
    
print(res)

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

bun_lis.sort()

total = 0
cnt = 1
bun_lis.append('XXX') 

def pea(n):
    return int(n*(n-1)/2)

for n in range(N):
    if bun_lis[n] != bun_lis[n+1]:
        total += pea(cnt)
        cnt = 1
        continue
    cnt += 1

print(total)

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

samedic={}
for s in ss:
  sort_s=''.join(sorted(list(s)))
  if sort_s in samedic:
    samedic[sort_s]+=1
  else:
    samedic[sort_s]=1

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

Solution (Python):

N = int(input())
ans = 0
ss = []
for _ in range(N):
    s = input()
    s = list(s)
    s.sort()
    s = "".join(s)
    ss.append(s)
ss.sort()
now = ss[0]
ruiseki = 0
for i in range(1,N):
    if ss[i] == now:
        ruiseki +=1
        ans += ruiseki
    else:
        ruiseki = 0
        now = ss[i]
print(ans)

Solution (Python):
import math
import sys
import numpy as np
from collections import defaultdict, deque, Counter 
from itertools import accumulate, product, permutations,combinations, combinations_with_replacement
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd

max_value = 1000000000
min_value = -1000000000
sys.setrecursionlimit(max_value)

N = int(input())
counter = defaultdict(int)

value = 0
for i in range(N):
    sorted_str = ''.join(sorted(input()))
    value += counter[sorted_str]
    counter[sorted_str] += 1
print(value)

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

samedic={}
for s in s_list:
    sorder=''.join(sorted(list(s)))
    if sorder in samedic:
        samedic[sorder]+=1
    else:
        samedic[sorder]=1

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

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


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

sorted_strings = [''.join(sorted(s)) for s in strings]
num_strings = Counter(sorted_strings).values()

num_anagram = int(sum(factorial(num) / (factorial(num-2) * 2) if num >= 2 else 0
                      for num in num_strings))
print(num_anagram)

Solution (Python):
from collections import defaultdict

n = int(input())

dic = defaultdict(int)
for _ in range(n):
  s = ''.join(sorted(input()))  
  dic[s] +=  1
  
ans = sum(v*(v-1)/2 for v in dic.values())  
print(int(ans))

Solution (Python):
ans = 0
N = int(input())
s_list = [''.join(sorted(input())) for _ in range(N)]
s_list.sort()

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

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

print(int(ans))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = []
for _ in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    lst.append(s)
lst = list(Counter(lst).items())
ans = 0
for i,j in lst:
    if j == 1:
        continue
    ans += ((j-1)*j)//2
print(ans)

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

ss = sorted(ss)

res = 0
while True:
    if len(ss) <= 1:
        break
    if ss[0] != ss[1]:
        ss.pop(0)
        continue
    i = 1
    while True:
        if i == len(ss):
            res += i * (i-1) / 2
            for num in range(i):
                ss.pop(0)
            break
        if ss[0] == ss[i]:
            i += 1
        else:
            res += i * (i-1) / 2
            for num in range(i):
                ss.pop(0)
            break

print(int(res))

Solution (Python):
a = int(input())
b = {}
strings = ''
ans = 0

for i in range(a):
    check = False
    strings = ''.join(sorted(list(input())))
    if strings in b.keys():
      check = True
    if check == True:
      ans += b[strings]
      b[strings] += 1
    else:
      b[strings] = 1

print(ans)

Solution (Python):
a = int(input())
b = {}
strings = ''
ans = 0

for i in range(a):
    check = True
    strings = ''.join(sorted(list(input())))
    if strings not in b.keys():
      check = False
      b[strings] = 1
    if check == True:
      ans += b[strings]
      b[strings] += 1

print(ans)

Solution (Python):
from collections import Counter

cnt = int(raw_input())
lines = []
for i in range(cnt):
    line = sorted([s for s in raw_input()])
    line = ''.join(line)
    lines.append(line)
counters = Counter(lines)
total = 0
for elm, counter in counters.items():
    total += sum(range(1, counter))
print total

Solution (Python):



import collections

"""
英子文字 26 個を素数で置き換えて掛け合わせると、アナグラムの組は同じ値となる。
1 <= i < j <= n であって、 si が sj のアナグラムであるようなものの個数を求める。
"""


def eratosthenes_sieve(n):
    primes = [2]
    for odd in range(3, n + 1, 2):
        for p in primes:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                primes.append(odd)
                break
    return primes



Era = eratosthenes_sieve(150)  
chars = "abcdefghijklmnopqrstuvwxyz"  
N = int(input())
array = [0] * N
for i in range(N):
    new = input()
    var = 1
    for j in range(10):
        h = chars.index(new[j])
        var *= Era[h]
    array[i] = var


kinds = collections.Counter(array)
kind = list(kinds.values())
print(sum(kind[i] * (kind[i] - 1) // 2 for i in range(len(kinds))))

"""

Counter は辞書型 dict のサブクラスで、キーに要素、値に出現回数という形のデータを持つ。
キーのリスト（keys()メソッド）、値のリスト（values()）、
キーと値のペアのタプルのリスト（items()メソッド）を取得したりできる。
リストに変換したい場合はlist()を使えばよい。
"""

Solution (Python):
N = int(input())
str_unions = sorted([tuple(sorted(input())) for _ in range(N)])
count_dict = {}
ret = 0

for s in str_unions:
    if s not in count_dict:
        count_dict[s] = 1
    else: count_dict[s] += 1

sum_n = lambda n: n*(n+1)//2
print(sum(map(lambda x:sum_n(x-1), count_dict.values())))

Solution (Python):
import collections
n=int(input())
l=[]
for _ in range(0, n):
  s=list(input())
  s.sort()
  l.append("".join(s))
cc=collections.Counter(l)
i=0
for k, v in cc.items():
  if v >= 2:
    i+=(v*(v-1))/2
print(int(i))

Solution (Python):
from collections import Counter

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

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

c = Counter(s)


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

print(ans)

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

ans = 0
d = dict()
for _ in range(n):
    s = input()
    t = sorted(list(s))
    t = ''.join(t)
    if t not in d: d[t] = 1
    else: 
        ans += d[t]
        d[t] += 1

print(ans)

Solution (Python):


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

    c = {}
    ans = 0
    for s in l:
        if s in c:
            c[s] = c[s] + 1
        else:
            c[s] = 0
        ans += c[s]

    print(ans)

main()

Solution (Python):
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
count = {}
ans = 0
for i in s:
    count[i] = count.get(i, 0) + 1
for key, value in count.items():
    ans += value * (value - 1) // 2
print(ans)

Solution (Python):
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
S = sorted(S)
c = 0
i = 0
while i < n - 1:
  j = i + 1
  while j < n:
    if S[i] == S[j]:
      j += 1
    else:
      break
  c += (j-i) * (j-i-1) // 2
  i = j  
print(c)

Solution (Python):
from collections import defaultdict
x=defaultdict(int)
N=int(input())
for i in range(N):
    x[''.join(sorted(input()))]+=1
an=0
for i in x.values():
    an+=int(i*(i-1)/2)
print(an)

Solution (Python):
import sys
from collections import Counter
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
s=[input() for i in range(n)]
ans=0
dic={}
for i in range(n):
    tmp=list(s[i])
    tmp.sort()
    tmp="".join(tmp)
    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())
d = {}
ans = 0
for i in range(n):
    s = str(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

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

count = {}

for v in s:
    count[v] = count.get(v, 0) + 1

def sig(k):
    return ((k + 1) * k) // 2

ans = 0
for key, value in count.items():
    ans += (sig(value - 1))
print(ans)

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

s1 = []
t1 = ""
d1 = {}
for i1 in range(n1):
    t1 = ''.join(sorted(input()))
    if d1.get(t1, 0) == 0:
        d1[t1] = 1
    else:
        d1[t1] += 1

r1 = 0

for v1 in d1.values():
    if v1 != 1:
        r1 += ((v1 * (v1 - 1)) // 2)

print(r1)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n = int(input())
l = [str(sorted(str(input()))) for _ in range(n)]
 
d = {}
 
for i in range(n):
  s = l[i]
  
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

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

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

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  w=sorted(list(input()))
  l.append(w)
l=sorted(l)
c=0
c1=0
w1=l[0]
for i in range(n):
  if w1==l[i]:
    c1+=1
  else:
    w1=l[i]
    c+=c1*(c1-1)//2
    c1=1
    
c+=c1*(c1-1)//2
print(c)

Solution (Python):

def main():
    count = 0
    dictCount = {}
    for i in [input() for i in range(int(input()))]:
        strInput = ''.join(sorted(i))
        if strInput in dictCount:
            count += dictCount[strInput]
            dictCount[strInput] += 1
        else:
            dictCount[strInput] = 1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):

def main():
    count = 0
    dictCount = {}
    for i in [input() for i in range(int(input()))]:
        strInput = ''.join(sorted([c for c in i]))
        if strInput in dictCount:
            count += dictCount[strInput]
            dictCount[strInput] += 1
        else:
            dictCount[strInput] = 1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
import collections

n = int(input())

counter = collections.Counter()
for _ in range(n):
    s = ''.join(sorted(input()))
    counter[s] += 1

res = 0
for value in counter.values():
    if value > 1:
        res += value * (value - 1) // 2

print(res)

Solution (Python):
import collections

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
s_c = collections.Counter(s)
print(sum(i*(i-1)//2 for i in s_c.values()))

Solution (Python):
import math
def combo(a):
    return (math.factorial(a))/(math.factorial(a-2)*2)

from collections import Counter
n = int(input())
count = 0
string = [input() for i in range(n)]
string2 = [''.join(sorted(x)) for x in string]

'''for i in range(n-1):
    for j in range(i+1, n):
        if string2[i] == string2[j]:
            count += 1'''
li = Counter(string2)
li1=[[key,value] for key, value in li.items()]
for i in range(len(li1)):
    if li1[i][1] == 1:
        li1[i][1] = 0
for i in range(len(li1)):
    if li1[i][1] != 0:
        li1[i][1] = combo(li1[i][1])
for i in range(len(li1)):
    count += li1[i][1]
print(int(count))

Solution (Python):
def dns(n):
    fact = [0, 0, 1]
    for i in range(2, n+1):
        fact.append(fact[-1]+i)
    return fact


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

hoge = dns(100008)

anagram_dict = {}

new_S = []

for s in S:
    tmp = "".join(sorted(list(s)))
    new_S.append(tmp)

for s in new_S:
    anagram_dict.setdefault(s, 0)
    anagram_dict[s] += 1

ans = 0
for v in anagram_dict.values():
    ans += hoge[v]

print(ans)

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

S_dict = {}

for S in S_lists:
    S_list = list(S)
    S_list.sort()

    S_str = "".join(S_list)
    if S_str in S_dict.keys():
        S_dict[S_str] = S_dict[S_str] + 1
    else:
        S_dict[S_str] = 1

answer = 0
for v in S_dict.values():
    if v > 1:
        answer += int(v * (v - 1) / 2)

print(answer)

Solution (Python):
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
count=[[0]*26 for _ in range(n)]
ans=0
for i in range(n):
    for j in range(10):
        count[i][ord(s[i][j])-ord("a")]+=1
for i in range(n):
    count[i]=tuple(count[i])
for i in dict(Counter(count)).values():
    for j in range(i):
        ans+=j
print(ans)

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

Solution (Python):
n = int(input())
s = [input() for x in range(n)]
count = 0
d = {}

for i in range(n):
    s1 = list(s[i])
    s1.sort()
    string = "".join(s1)
    if (string not in d.keys()):
        d[string] = 0
    else:
        d[string] += 1
        count += d[string]

print(count)

Solution (Python):
N=int(input())
l=[]
from collections import Counter
for i in range(N):
  l.append(''.join(sorted(input())))
l1=Counter(l).values()
from math import factorial
ans=0
for a in l1:
  if a >= 2:
    ans+=int(factorial(a)/(factorial(a-2)*factorial(2)))
print(ans)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    str_cnt = defaultdict(int)
    for _ in range(N):
        s = str(sorted(ST()))
        str_cnt[s]+=1
    ans = 0
    for cnt in str_cnt.values():
        ans += cnt*(cnt-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    str_cnt = defaultdict(int)
    for _ in range(N):
        s = str(sorted(ST()))
        str_cnt[s]+=1
    ans = 0
    for cnt in str_cnt.values():
        ans += cnt*(cnt-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s = [ str(input()) for _ in range(n)]
s = sorted([sorted(x) for x in s])
pairs = 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

i=0
while i < n-1:
    sames = 0
    for j in range(i+1, n):
        if s[i] == s[j]:
            sames += 1
            continue
        else:
            break
    i += sames + 1
    if sames != 0:
        pairs += combinations_count(sames + 1, 2)


print(int(pairs))

Solution (Python):
from collections import defaultdict

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]

cnts = defaultdict(int)

for s in S:
    cnts[s] += 1

res = 0

for _, v in cnts.items():
    res += v * (v - 1) // 2

print(res)

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

sorted_input = ["".join(sorted(i)) for i in input_str]

count = collections.Counter(sorted_input)

result = 0
for num in count.values():
    result += num * (num - 1) / 2



print(int(result))

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

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

Solution (Python):

from collections import Counter

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


ctr = Counter()
ctr = {}
ans = 0

for s in S:
    
    
    a = ''.join(sorted(list(s)))

    
    
    
    
    
    if a in ctr:
        ans += ctr[a]
    else:
        ctr[a] = 0

    ctr[a] += 1

print(ans)

Solution (Python):
from collections import Counter


n = int(input())
ss = ["".join(sorted(input())) for _ in range(n)]
c = Counter(ss)
total = 0
for a, b in c.most_common(len(c)):
    total += (b * (b - 1)) // 2
print(total)

Solution (Python):
def return_sorted_string(string):
    lst=list(map(ord,list(string)))
    lst.sort()
    lst=list(map(chr,lst))
    string="".join(lst)
    return string
    



n = int(input())
strings=[input() for i in range(n)]
dic={}
for i in range(n):
    string=return_sorted_string(strings[i])
    if string in dic:
        dic[string]+=1
    else:
        dic[string]=1

count=0        

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


print(int(count))

Solution (Python):
def stringtonum(s):
  s_n = list(map(ord, s))
  s_n.sort()
  res = 0
  for i, n in enumerate(s_n):
    res += (27**i) * (n-97)
  return res

d = {}
N = int(input())
for _ in range(N):
  s = input()
  n = stringtonum(s)
  if n in d:
    d[n] += 1
  else:
    d[n] = 1
    
res = 0
for v in d.values():
  res += v*(v-1)//2
print(res)

Solution (Python):
N=int(input())
count=0
S=[input() for i in range(N)]
d={}

for i in S:
    a=''.join(sorted([c for c in i]))
    if a in d:
        count+=d[a]
        d[a]+=1
    else:
        d[a]=1
print(count)

Solution (Python):
import string


def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    n = read_int(1)[0]
    s = []
    for _ in range(n):
        s.append(read_line())
    return s


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    dictionary_of_histogram = {}
    for line in s:
        key_of_histgram = make_key_for_histgram(line)
        if key_of_histgram in dictionary_of_histogram:
            dictionary_of_histogram[key_of_histgram] += 1
        else:
            dictionary_of_histogram[key_of_histgram] = 1

    result = 0
    for k, v in dictionary_of_histogram.items():
        if v >= 2:
            result += combination_2(v)
    return result


def make_key_for_histgram(s):
    key = ''
    for c in string.ascii_lowercase:
        count = s.count(c)
        if count > 0:
            key += ',{0:s}{1:d}'.format(c, count)
    return key


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


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

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

Solution (Python):
from collections import Counter

N = int(input())
str = ["".join(sorted(input())) for i in range(N)]

c = Counter(str)

print(sum(i*(i-1)//2 for i in c.values()))

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

Solution (Python):
N = int(input())
counters = []
for i in range(0, N):
	lst = []
	for j in range(0, 26):
		lst.append(0)
	S = input()
	for j in range(0, 10):
		lst[ord(S[j])-97] += 1
	counters.append(lst)
counters.sort()
cntlist = [1]
for i in range(1, N):
	if counters[i-1] == counters[i]:
		cntlist[-1] += 1
	else:
		cntlist.append(1)
ans = 0
for i in range(0, len(cntlist)):
	if cntlist[i] != 1:
		ans += (cntlist[i] * (cntlist[i]-1)) // 2
print(ans)

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

Solution (Python):
def solve():
    N = int(input())
    str_unions = sorted([tuple(sorted(input())) for _ in range(N)])
    count_dict = {}
    ret = 0
    
    for s in str_unions:
        if s not in count_dict:
            count_dict[s] = 1
        else: count_dict[s] += 1

    sum_n = lambda n: n*(n+1)//2
    
    print(sum(map(lambda x:sum_n(x-1), count_dict.values())))
    
solve()

Solution (Python):
from scipy.misc import comb
 
N = int(input())
s = {}
for _ in range(N):
    b = list(input())
    b.sort()
    c = ''.join(b)
    if not c in s:
        s[c] = 1
    else:
        s[c] += 1
 
a = [comb(v, 2, exact=True) for v in s.values()]
print(sum(a))

Solution (Python):
def solve():
    N = int(input())
    str_unions = sorted([sorted(input()) for _ in range(N)])
    ret = 0
    count_tmp = 1
    s_temp = []
    
    for s in str_unions:
        if s == s_temp:
            ret += count_tmp
            count_tmp += 1
        else:
            s_temp = s
            count_tmp = 1
    
    print(ret)

solve()

Solution (Python):
N = int(input())
l = ["".join(sorted(list(input()))) for i in range(N)]
d = {}
ans = 0

for text in l:
  if text in d.keys():
    d[text] += 1
    ans += d[text]
  else:
    d[text] = 0

print(ans)

Solution (Python):
import collections

N = int(input())
s_hist = collections.Counter()

for n in range(N):
    s = input().strip()
    s_hist[" ".join(sorted(s))] += 1

ans = 0
for pair in s_hist.most_common():
    ans += s_hist[pair[0]]*(s_hist[pair[0]]-1)/2
    if(pair[1] == 1):
        break
print(int(ans))