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

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

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

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

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

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
s = Counter()
for i in range(N):
    s[''.join(sorted(input()))] += 1
ans = 0
for kw, count in s.most_common():
    for i in range(1, int(count)):
        ans += i
    if int(count) < 2:
        break
print(ans)

Solution (Python):


N = int(input())
count = 0
word = {}
def str_sort(str):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(str)
for _ in range(N):
    sorted_str = str_sort(input())
    if sorted_str not in word:
        word[sorted_str] = [0]
        word[sorted_str].append(1)
    else:
        if word[sorted_str] == 0:
            word[sorted_str][0] = 1
        else:
            word[sorted_str][0] += word[sorted_str][1]
            word[sorted_str][1] += 1
            
total = sum(
    v[0] for v in word.values()
)

print(total)

Solution (Python):
import collections
n = int(input())
s = [list(input()) for i in range(n)]
l = [''.join(sorted(i)) for i in s]
c = list(collections.Counter(l).values())
x = sum([sum([i for i in range(i)]) for i in c if i != 1])
print(x) if 0 < x else print(x)

Solution (Python):
import sys
input = sys.stdin.readline
 
N = int(input())
words = {}
while N > 0:
    word = ''.join(sorted(input().rstrip()))
    if word in words:
        words[word] += 1
    else:
        words[word] = 1
    N -= 1

count = 0
for n in words.values():
    if n > 1:
        count += n*(n-1) // 2

print(count)

Solution (Python):
import collections

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

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

    
print(ans)

Solution (Python):
n = int(raw_input())
strings = [raw_input() for _ in xrange(n)]
hashes = {}
for s in strings:
  h = ''.join(sorted(s))
  hashes[h] = hashes.get(h, 0) + 1
total = 0
for c in hashes.itervalues():
  total += c * (c-1)
print total/2

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

ans = 0
cnt = {}

for s in S:
    s = "".join(sorted(s))
    if s in cnt:
        ans += cnt[s]
        cnt[s] += 1
    else:
        cnt[s] = 1

print(ans)

Solution (Python):
d={}
c=0
for i in open(0):i=str(sorted(i));t=d.get(i,0);c+=t;d[i]=t+1
print(c)

Solution (Python):

n = int(raw_input())
s = [''.join(sorted(raw_input())) for _ in range(n)]
d = {}
ans = 0
for si in s:
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

Solution (Python):

n = int(raw_input())
d = {}
ans = 0
for i in range(n):
    si = ''.join(sorted(raw_input()))
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

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

for s in S:
    s.sort()
S.sort()

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

print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    tmp = list(input())
    tmp.sort()
    S.append(''.join(tmp))
cnt = 0

mydict = {}

for i in range(N):
    if (S[i] in mydict.keys()) == False:
        mydict[S[i]] = 0
    else:
        cnt += mydict[S[i]]+1
        mydict[S[i]] += 1

print(cnt)

Solution (Python):
ROW = int(input())
LIST = [input() for i in range(ROW)]

dic={}
ans=0
for i in LIST:
    j = " ".join(sorted(i))

    if j in dic:
        ans+= dic[j]
        dic[j] += 1
    else:
        dic[j] = 1

print(ans)

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

s = []
ans = 0
count = 1

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

s.sort()

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

print(int(ans))

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

Solution (Python):
import collections
import itertools
ans = 0

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

d = {}
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    if a in d:
        ans+=d[a]
        d[a]+=1
    else:
        d[a] = 1

print(ans)

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

H=[]
c=0
t=0
for i in range(N):
    h=list(input())
    h.sort(reverse=False)
    H.append(h)

H.sort(reverse=False)

for j in range(N-1):
    
    if H[j]==H[j+1]:
        c+=1

    else:
        t+=int((c)*(c+1)/2)
        c=0

if c:
    t+=int(((c)*(c+1)/2))
        

print(t)

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

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

S=[]
ans = 0
count=1

for i in range(n):
    tmp=input()
    S.append(sorted(tmp))

S.sort()

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

ans+=count*(count-1)/2

print(int(ans))

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(100000000)
 
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
count = 0
memo = [0]*10**6
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]
        
print(count)

Solution (Python):
N=int(input())
C=[]
dic={}
ans=0
for i in range(N):
  a=str(input())
  C.append(a)
for i in C:
  ab=[j for j in i]
  ab.sort()
  aaa="".join(ab)
  
  if aaa in dic:
    ans+=dic[aaa]
    dic[aaa]+=1
  else:
    dic[aaa]=1
print(ans)

Solution (Python):

n=int(input()) 
s = []
for i in range(n):
    s.append(list(input()))
d = {}
ans = 0
for i in s:
    a = [c for c in i]
    a.sort()
    a = "".join(a)
    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 = []
for i in range(N):
    S.append(list(input()))

    
cnt = Counter()
ans = 0
for s in S:
    
    a = ''.join(sorted(list(s)))
    
    if a in cnt:
        
        ans += cnt[a]
    
    cnt[a] += 1
print(ans)

Solution (Python):
n = int(input())
lst = []
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if s not in dic.keys():
        dic[s] = 1
    else:
        dic[s] += 1

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

print(ans)

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

N = int(input())

diclist = []

i=0
while i < N:
  temp = list(input())
  temp.sort()
  tmp_el = ''.join(temp)
  diclist.append(tmp_el)
  i += 1
  
c = collections.Counter(diclist)
clist = list(c.values()) 
ccomb = [comb(clist[i], 2, exact = True) for i in range(0,len(clist))]

print(sum(ccomb))

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

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

count = 0
d = {}
for elm in s:
    if elm in d:
        count += d[elm]
        d[elm] += 1
    else:
        d[elm] = 1

print(count)

Solution (Python):
n,*sl, = map(lambda x:''.join(sorted(x)),open(0).read().split())
count = 0
dict = {}
for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

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

dic = {}
ans = 0

for ss in s:
    temp = [ch for ch in ss]
    temp.sort()
    sss = "".join(temp)
    
    if sss in dic:
        ans += dic[sss]
        dic[sss] += 1
    else:
        dic[sss] = 1

print(ans)

Solution (Python):
from collections import defaultdict
import sys
readline = sys.stdin.readline
C = defaultdict(int)
N = int(readline())
ans = 0
for i in range(N):
    *s, = readline()
    s.sort()
    t = tuple(s)
    ans += C.get(t, 0)
    C[t] += 1
print(ans)

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

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

import collections

c = collections.Counter(s)


ans = 0

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

print(ans)

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

s = []
for _ in range(n):
    s += [''.join(map(str, (sorted(list(str(input()))))))]

import collections

c = collections.Counter(s)

ans = 0

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

print(ans)

Solution (Python):
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
s=["".join(sorted(stdin.readline().rstrip())) for _ in range(n)]
t=Counter(s).values()
ans=0
for i in t:
    ans+=sum(range(1,i))
print(ans)

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

ans = 0
for _ in range(N):
    w = list(input())
    w.sort()
    w = "".join(w)
    if w not in words:
        words[w] = 1
    else:
        ans += words[w]
        words[w] += 1
print(ans)

Solution (Python):
num = int(input())
arr = []
d = {}

for i in range(num):
    s = sorted(list(input()))
    ss = ''.join(s)
    arr.append(ss)


ans = 0

for i in range(num):
    if arr[i] in d:
        ans += d[arr[i]] 
        d[arr[i]] += 1
    else:
        d[arr[i]] = 1

print(ans)

Solution (Python):
def f_c():

    n = int(input())
    d = {}
    dc = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in d:
            dc[s] += d[s]
            d[s] += 1
        else:
            d[s] = 1
            dc[s] = 0
    print(sum(dc.values()))

if __name__ == "__main__":
    f_c()

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

s = ''.join(sorted(input()))
h = {s: 1}
count = 0
for i in range(N - 1):
    
    s = ''.join(sorted(input()))
    if s in h:
        count += h[s]
        h[s] += 1
    else:
        h[s] = 1

print(count)

Solution (Python):
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
t=Counter(s).values()
ans=0
for i in t:
    ans+=sum(range(1,i))
print(ans)

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


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



sort_str = {}

counter = 0
for i in range(N):
    s = ''.join(sorted(S[i]))
    if s in sort_str:
        counter += sort_str[s]
        sort_str[s] += 1 
    else:
        sort_str[s] = 1
print(counter)

Solution (Python):
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

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

Solution (Python):
import glob
import numpy as np
import heapq



REL_PATH = 'ABC\\137\\C'


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        N = int(self.input_data())
        problem = ["" for i in range(N)]

        for i in range(N):
            tmp = self.input_data()
            tmp = list(tmp)[0:10]
            tmp.sort()
            for j in range(10):
                problem[i] += tmp[j]

        problem.sort()
        con_num = 1
        now = ""
        result = 0

        for s in problem:
            if now == s:
                con_num += 1
            else:
                result += int(con_num * (con_num-1) / 2)
                con_num = 1
                now = s
        result += int(con_num * (con_num - 1) / 2)

        print(str(result))


solver = C(REL_PATH)
solver.exec_resolve()

Solution (Python):
n = int(input())
sl = [''.join(sorted(input())) for _ in [0]*n]
count = 0
dict = {}
for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Solution (Python):
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Solution (Python):
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    
    dict[s] += 1
  else:
    dict.setdefault(s, 1)
for s in dict:
  count += dict[s]*(dict[s]-1)//2
print(count)

Solution (Python):
import sys
import collections
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(sys.stdin.readline().rstrip())
SList=[]
for i in range(N):
  S=sys.stdin.readline().rstrip()
  SList.append("".join(sorted(S)))
  
c = collections.Counter(SList)

ans=0
for v in c.values():
  if v<=1:
    continue
  ans+=combinations_count(v, 2)
print(ans)

Solution (Python):
n = int(input())
a = []
for i in range(n):
  a.append(input())
for i in range(n):
  k = list(a[i])
  k.sort()
  k = ''.join(k)
  a[i] = k
a.sort()
k = 1
s = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    k += 1
  else:
    s += k*(k-1)/2
    k = 1
s += k*(k-1)/2
print(int(s))

Solution (Python):
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict.setdefault(s, 1)
print(count)

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


from collections import Counter
counter = Counter(S)
answer = sum(x * (x - 1) // 2 for x in counter.values())
print(answer)

Solution (Python):
from collections import defaultdict
N = int(input())
S = [''.join(sorted(list(str(input())))) for i in range(N)]

countDict = defaultdict(int)
ans = 0
for s in S:
    ans += countDict[s]
    countDict[s] += 1
print(ans)

Solution (Python):
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin
 
def main():
    n = int(input())
    S = ["".join(sorted(input())) for _ in range(n)]

    ans = 0
    dd = defaultdict(int)
    for s in S:
        ans += dd[s]
        dd[s] += 1
    print(ans)
 
input = lambda: stdin.readline().rstrip()
main()

Solution (Python):

n = int(input())
lista= [''.join(sorted(input())) for _ in range(n)]
 
dic = {}
ans = 0
for word in lista:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1
 
print(ans)

Solution (Python):
Ncount = input()
strings = []
count_flag = 0
letters = {}
for i in range(int(Ncount)):
  strings.append(''.join(sorted(input())))

for i in strings:
  if i not in letters:
    letters[i] = 0
  else :
    letters[i] += 1
    count_flag += letters[i]

print(count_flag)

Solution (Python):
from collections import Counter
from sys import stdin


def main():
    n = int(input())
    anas = Counter(''.join(sorted(stdin.readline())) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)
    print(result)


main()

Solution (Python):
n = int(input())
s = [[x for x in input()] for _ in range(n)]
ans = 0
d = {}
for i in range(n):
    key = "".join(sorted(s[i]))
    if key in d:
        ans += d[key]
        d[key] += 1
    else:
        d[key] = 1

print(ans)

Solution (Python):
import numpy as np
import collections

n = int(input())
s = np.array([[str(i) for i in input().split()] for i in range(n)])
s = np.ravel(s)
ans = 0
sorted_list = [''.join(sorted(e)) for e in s]

c = collections.Counter(sorted_list)
for i in c.values():
  for j in range(0, i):
    ans += j

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
SList = [''.join(sorted(input())) for _ in range(N)]

dic = {}
ans = 0
for word in SList:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1

print(ans)

Solution (Python):
from collections import Counter

N=int(input())
ls=[sorted(list(input())) for _ in range(N)]
ls.sort()

l=[]
for i,s in enumerate(ls):
    if i == 0:
        l.append(1)
        continue
    
    if ls[i-1] == s:
        l[-1]+=1
    else:
        l.append(1)
sol=0
for e in l:
    if e==1:
        continue
    
    sol+=int(0.5*(e-1)*e)

print(sol)

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

ds={}
for i in range(N):
    s=input()
    
    
        
            
        
            
    
    s="".join(sorted(s))

    
    
    
    
    
    
    

    if s in ds:
        ds[s]+=1
    else:
        ds[s]=1

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


    
        
        

    
    
    
print(int(ans))

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	s = [input() for _ in range(n)]
	a = defaultdict(int)
	for i in s:
		t = ''
		for j in sorted(i):
			t += j
		a[t] += 1
	ans = 0
	for v in a.values():
		ans += v * (v-1) // 2
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    anas = Counter(''.join(sorted(input())) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)
    print(result)


main()

Solution (Python):
import math
from collections import Counter


N = int(input())

def sort_string(s):
    s = list(s)
    s.sort()
    
    return ''.join(s)

S = [sort_string(input()) for _ in range(N)]
c = Counter(S)

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

count = 0
for s in c.values():
    if s > 1:
        count += combinations_count(s, 2)

print(count)

Solution (Python):
n = int(input())
d = dict()
for _ in range(n):
  l = "".join(sorted(list(input()))) 
  if l not in d:
    d[l] = 0
  d[l] += 1
ans = 0
for x in d.values():
  ans += x*(x-1)//2
print(ans)

Solution (Python):
N = int(input())
s = []
s = [input() for i in range(N)]
count = 0
a = []
sortdict = {}
for i in range(N):
    a = str(sorted(s[i]))
    if a in sortdict:
        sortdict[a] += 1
    else:
        sortdict[a] = 0
sort_list = list(sortdict.values())
for i in range(len(sort_list)):
    sort_list[i] = int((sort_list[i])*(sort_list[i] + 1)/2)
 

print(sum(sort_list))

Solution (Python):

def main():
    N = int(input())
    d = {}
    ans = 0
    for _ in range(N):
        s = "".join(sorted(list(input())))
        if s in d:
            ans += d[s]
            d[s] += 1
        else:
            d[s] = 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = []
for i in range(n):
    c = list(input())
    c.sort()
    a.append(''.join(c))
a.sort()
sol = 0
i = 0
while i < len(a):
    j = i + 1
    temp = 1
    while j < len(a) and a[j] == a[i]:
        j += 1
        temp += 1
    i = j
    if temp == 0 or temp == 1: continue
    if temp == 2:
        sol += 1
        continue
    if temp == 3:
        sol += 3
        continue
    else:
        sol += (temp * (temp - 3) // 2 + temp)
print(sol)

Solution (Python):
N = int(input())
ss = ["".join(sorted(list(input()))) for _ in range(N)]

from collections import Counter
d = Counter(ss)

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

print(int(cnt))

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

    count = 0
    found = {}
    for _ in range(n):
        strs = list(input())
        strs.sort()
        str = ''.join(strs)
        if str in found:
            count += found[str]
            found[str] += 1
        else:
            found[str] = 1

    print(count)


if __name__ == "__main__":
    main()

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

    count = 0
    found = {}
    for _ in range(n):
        str = ''.join(sorted(input()))
        if str in found:
            count += found[str]
            found[str] += 1
        else:
            found[str] = 1

    print(count)


if __name__ == "__main__":
    main()

Solution (Python):


N = int(input())
S = []
for i in range(N):
    t = input()
    l = []
    for a in t:
        l.append(ord(a)-ord('a'))
    l.sort()
    v = 0
    for a in l:
        v = v * 26 + a
    S.append(v)

S.sort()
S.append(-1)

P = -1
C = 0
Ans = 0
for v in S:
    if P != v:
       Ans += int(C * (C - 1) / 2)
       C = 1
    else:
        C += 1
    P = v

print(Ans)

Solution (Python):

from collections import Counter

n=int(input())  
count_by_kw = Counter()
for i in range(n):
    count_by_kw[''.join(sorted(input()))]+=1

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

Solution (Python):
from collections import defaultdict
dic = defaultdict(int)

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

ans = 0
for j in range(len(s)):
    mozi = sorted(s[j])
    mozi_s = "".join(mozi)
    ans += dic[mozi_s]
    dic[mozi_s] += 1
    
print(ans)

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

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

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


dic = {}

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

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

print(ans)

Solution (Python):
N = int(input())
S = [""] * N
for n in range(N):
    S[n] = input()
from collections import defaultdict
dct = defaultdict(int)
for s in S:
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1
ans = 0
for k,v in dct.items():
    ans += v*(v-1)//2
print(ans)

Solution (Python):

from sys import stdin

n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip() for _ in range(n)]
new = []
for i in range(n):
    sort = sorted(data[i])
    sorting = "".join(sort)
    new.append(sorting)
new.sort()
score = 0
s = 0
count  = 0
while s<n-1:
    daburi = 1
    for p in range(s,n-1):
        if new[p] == new[p+1]:
            daburi += 1
        else:
            break
    score += daburi*(daburi-1)//2
    count += daburi
    s = count
print(score)

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


res = 0
d = {}
for _ in range(n):
    ss = list(input())
    ss.sort()
    s = ''.join(ss)
    if s in d:
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(res)

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


for i in range(len(S)):
    s = S[i]
    t = list(s)
    t.sort()
    S[i] = ''.join(t)

S.sort()


ans = 0
count = 0
for i in range(N - 1):
    si = S[i]
    sj = S[i + 1]
    if si != sj:
        ans += count * (count + 1) // 2
        count = 0
    else:
        count += 1
        if i == N - 2:
            
            ans += count * (count + 1) // 2

print(ans)

Solution (Python):
n = int(input())
data = []
for i in range(n):data.append(sorted(input()))
data, backup, ans, temp = sorted(data), [], 0, 1
for i in data:
    if backup==i:temp+=1
    else:ans, temp = ans + int(temp*(temp-1)/2), 1
    backup = i
ans+= int(temp*(temp-1)/2)
print(ans)

Solution (Python):
from sys import exit, stdin
from operator import mul
from functools import reduce
from collections import Counter
N = int(stdin.readline().rstrip())
S = Counter(''.join(sorted(list(stdin.readline().rstrip()))) for _ in range(N))

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans = 0
for i in S.values():
    if i > 1:
        ans += cmb(i, 2)
print(ans)

Solution (Python):
num = int(input())
li = [input() for i in range(num)]

dic = {}
ans = 0
for i in range(num):
    now = "".join(sorted(li[i]))
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
for i in dic:
    n = dic[i]
    ans += int((n*(n-1))/2)

print(ans)

Solution (Python):
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Solution (Python):
import collections
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
s_cnt=collections.Counter(s)
ans=sum(i*(i-1)//2 for i in s_cnt.values())
print(ans)

Solution (Python):
N = input()
sum = 0
mydict = {}
for i in range(int(N)):
    s = list()
    st2 = ""
    st = input()
    for i in range(10):
        s.append(st[i])
    s.sort()
    if st2.join(s) in mydict.keys():
        mydict[st2.join(s)] += 1
        sum += mydict[st2.join(s)]
    else:
        mydict[st2.join(s)] = 0

print(sum)

Solution (Python):
def sort_str(s):
    l = list(s)
    l.sort()
    return ''.join(l)

n = int(input())
counts = dict()
for _ in range(n):
    s = input()
    s = sort_str(s)
    counts.setdefault(s, 0)
    counts[s] += 1
ans = 0
for c in counts.values():
    ans += c * (c - 1) // 2
print(ans)

Solution (Python):
N = int(input())
s = [input() for k in range(N)]
s = [''.join(sorted(list(s_element))) for s_element in s]
memory = {}
result = 0
for s_element in s:
    if s_element not in memory:
        memory[s_element] = 1
    else:
        result += memory[s_element]
        memory[s_element] += 1
print(result)

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


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += str(v)
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c = [count_abc(st) for st in s]
  
  c_dict = collections.Counter(s_c)
  
  ans = 0
  
  for v in c_dict.values():
    if v > 1:
      ans += comb(v, 2, exact=True)
  
  print(ans)

  
if __name__ == "__main__":
  main()

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