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 bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    d = Counter()
    for s in S:
        d[tuple(sorted(s))] += 1
    return reduce(lambda x, y: x + (y*(y-1))//2, d.values(), 0)


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def cmb(n,r):  
    retVal = 1
    for i in range(n-r+1,n+1):
        retVal *= i
    for i in range(2,r+1):
        retVal //= i
    return retVal
def main():
    from collections import defaultdict
    N = int(input())
    d = defaultdict(lambda:0)
    base = ord('a')
    ans = 0
    for _ in range(N):
        s = input().strip()
        num = 0
        for c in s:
            num += 26 ** (ord(c) - base)
        ans += d[num]
        d[num] += 1

    
    print(ans)

        

    





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

Solution (Python):
n = int(input())
ln = []
cnt = 1
ans = 0

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

ln.sort()

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

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

print(int(ans))

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

mp = {}
for c in s:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1

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

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


from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for i in range(N):
    S[i] = sorted(S[i])
    d["".join(S[i])] += 1
ans = 0
for i in d.values():
    if i >= 2:
        ans += cmb(i, 2)

print(ans)

Solution (Python):
N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		

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

Solution (Python):
import math
a=int(input())
b=[sorted(input()) for j in range(a)]
b.sort()
sum=0
c=1
for i in range(a-1):
  if b[i]==b[i+1]:
    c+=1
  else:
    sum+=c*(c-1)//2
    c=1
  if i==a-2:
    sum+=c*(c-1)//2
    
print(sum)

Solution (Python):
from collections import Counter

N = int(input())
counter = Counter()
for i in range(N):
    counter[tuple(sorted(input()))] += 1

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

print(int(res))

Solution (Python):

def combinatnion(num, cmb):
    nmrtr = 1
    dnmntr = 1

    for i in range(cmb):
        nmrtr = nmrtr * (num - i)
        dnmntr = dnmntr * (i + 1)

    ans = int(nmrtr/dnmntr)
    return ans

n = int(input())

inputList=[]
for i in range(n):
    line = input()
    inputList.append(line)



sortedList = []
dic = {}
for i in range(n):
    tmpList = list(inputList[i])
    tmpList.sort()
    tmpword = "".join(tmpList)

    if tmpword in dic:
        dic[tmpword] = dic[tmpword] + 1
    else:
        dic[tmpword] = 1

    



cnt = 0
for val in dic.values():
    if val != 1:
        cnt += combinatnion(val, 2)

print(cnt)

Solution (Python):
N = input().split()
N = int(N[0])
d={}
score = 0

for i in range(N):
  S = input()
  S = sorted(S)
  S = ''.join(S)
  
  if S in d:
    score += d[S]
    d[S] +=1
  else:
    d[S] = 1
    
print(score)

Solution (Python):
from collections import defaultdict

n = int(input())
d = defaultdict(int)
ans = 0
for _ in range(n):
    s = input()
    s = str(sorted(s))
    ans += d[s]
    d[s] += 1

print(ans)

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

Solution (Python):
ans = 0
s = {}
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	tmp.sort()
	stmp = ''.join(tmp)
	if stmp in s and s[stmp] > 0:
		ans += s[stmp]
		s[stmp] = s[stmp]+1
	else:
		s[stmp] = 1
print(ans)

Solution (Python):

N = int(input())

cnt_dict = {}

for i in range(N):
    s_list = list(input())
    s_list.sort()
    s_str = "".join(s_list)
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += cnt * (cnt - 1) // 2

print(total)

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

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)

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

    if s in dic:
        ans+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(ans)

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

from collections import Counter
counter = Counter(s)
ans = sum(n*(n-1)//2 for n in counter.values())
print(ans)

Solution (Python):
import sys,math,collections
N = int(input())
s = []
ans = 0
for i in range(N):
    li_tmp = list(input())
    li_tmp.sort()
    st = "".join(li_tmp)
    s.append(st)
cnt = collections.Counter(s)
for i in cnt.values():
    if i != 1:
        ans += i*(i-1)//2
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
H = defaultdict(int)
for _ in range(N):
  S = input()
  H[''.join(sorted([s for s in S]))] += 1
cnt = 0
for v in H.values():
  cnt += v * (v - 1) // 2
print(cnt)

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

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

s.sort()

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

print(ans)

Solution (Python):

N=int(input())
S=[]
total=0

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

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Solution (Python):
import math

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

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)

Solution (Python):
import collections
n=int(input())
l=["".join(sorted(input())) for _ in range(n)]
c=collections.Counter(l)
mc=c.most_common()
ans=0
for i in mc:
    if i[1]>=2:
        ans+=i[1]*(i[1]-1)//2
print(ans)

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

c = 0
c1 =  0
p = sorted(q)
p.append("a")

for i in range(n):
	if p[i] == p[i+1]:
		c+=1
	else:
		
		if c>0:
			for j in range(c+1):
				c1+=j
				
		c=0
print(c1)

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

dic = {}
cnt = 0

for moji in moji_lst:
    x = ''.join(sorted(moji))

    if x in dic:
        dic[x] += 1
        cnt += dic[x]
    else:
        dic[x] = 0


print(cnt)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
d = {}
ans = 0
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
for string in s:
    if string in d:
        ans += d[string]
        d[string] += 1
    else:
        d[string] = 1
print(ans)

Solution (Python):
from collections import Counter
 
N = int(input())
 
ans = {}
answer = 0
for _ in range(N):
    s = "".join(sorted(input()))
 
    if s not in ans:
        ans[s] = 0
 
    else:
        ans[s] += 1
        answer += ans[s]
 
print(answer)

Solution (Python):

N = int(raw_input())
cnt = 0
dic = {}

for _ in xrange(N):
	rs = ''.join(sorted(raw_input()))
	
	if rs in dic:
		cnt += dic[rs]
		dic[rs] += 1
	else:
		dic[rs] = 1
print cnt

Solution (Python):
N = int(input())
D = {}
SUM = 0

for n in range(N):
  s = input()
  l = sorted(s)
  l = ''.join(l)
  
  if l in D:
    SUM = SUM + D[l]
    D[l] = D[l] + 1
  else:
    D[l] = 1
  
print(SUM)

Solution (Python):
n=int(input())
stats=[]
res={}

for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    if s in res:
        res[s]+=1
    else:
        res[s]=1

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

Solution (Python):



import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = dict()
    pairs = 0
    for i in s:
        i = ''.join(sorted(list(i)))

        if i in ans:
            pairs += ans[i]
            ans[i] += 1
            continue

        ans[i] = 1

    print(pairs)


if __name__ == '__main__':
    main()

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

dic = {}

for i in range(N):
	s = input()
	s = ''.join(sorted(s))
	if s in dic:
		dic[s] += int((-1+(1+8*(dic[s]))**0.5)/2)+1
	else:
		dic[s] = 0
print(sum(dic.values()))

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

Solution (Python):
import collections

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

counter = collections.Counter(s)

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

print(ans)

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

print(cnt)

Solution (Python):
from collections import Counter

def main():
    N = int(input())
    counter = Counter()
    for i in range(N):
        k = "".join(sorted(input().strip()))
        counter[k] += 1
    answer = 0
    for k, c in counter.items():
        answer += (c * (c-1)) // 2
    print(answer)

def main2():
    N = int(input())
    counter = Counter("".join(sorted(input().strip())) for i in range(N))
    print(sum((c * (c-1)) // 2 for c in counter.values()))

def main3():
    print(sum((c * (c-1)) // 2 for c in Counter("".join(sorted(input().strip())) for i in range(int(input()))).values()))


main3()

Solution (Python):
N = int(input())
ans = 0
dictionary = {}
for i in range(N):
	s = input()
	sorted_s = "".join(sorted([char for char in s]))
	if not sorted_s in dictionary:
		dictionary[sorted_s] = 0
	ans += dictionary[sorted_s]
	dictionary[sorted_s] += 1
print(ans)

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

dic = {}
for x in s:
  if dic.get(x) == None:
    dic[x] = 1
  else:
    dic[x] += 1

print(sum(map(lambda n: n*(n-1)//2,list(dic.values()))))

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

N = int(input())

dd=defaultdict(int)

Sread = sys.stdin.read()


for s in Sread.split('\n'):
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    
    dd[s]+=1






    
count = 0

for k in dd:
    s_counts = dd[k]
    if s_counts > 1:
        
        count += comb(s_counts, 2, exact=True)

print(count)

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

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()

Solution (Python):
from collections import Counter

N = int(input())
















ans = {}
answer = 0
for _ in range(N):
    s = "".join(sorted(input()))

    if s not in ans:
        ans[s] = 0

    else:
        ans[s] += 1
        answer += ans[s]

print(answer)

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

Solution (Python):
n = int(input())
ws = [list(input()) for _ in range(n)]
 
def sort_l(l):
    l.sort()
    return l
ws = list(map(sort_l, ws))
ws.sort()
 
i = 0
j = 0
r = 0
ans = 0
while(i<n-1):
    i += 1
    if ws[i] == ws[j]:
        r += 1
    else:
        ans += r * (r+1) // 2
        r = 0
        j = i
ans += r * (r+1) // 2
 
print(ans)

Solution (Python):
from collections import Counter
import sys

input = sys.stdin.readline
n = int(input())
str_list = [''.join(sorted(input().rstrip())) for i in range(n)]
ans = 0
count_list = list(Counter(str_list).values())
for i in count_list:
  sum = 0
  for j in range(int(i)):
    sum += j
  ans +=sum
print(ans)

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

Solution (Python):
N = int(input())
ss = {}
ht = []
ans = 0

for i in range(N):
    s = ''.join(sorted(input()))
    if not s in ss.keys():
        ss[s] = 1
    else:
        ss[s] += 1
        
for i in ss.keys():
    if ss[i] > 1:
        ans += int((ss[i]*(ss[i]-1))/2)

print(ans)

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

cnt = 0
s2c = {} 

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

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

import collections
import math

c = collections.Counter(S)
ans = 0
for i in c.values():
    if i == 1:
      continue
    else:
      ans += i*(i-1)//2
print(int(ans))

Solution (Python):
def main():
    n = int(input())
    count = 0
    count_dict = {}
    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in count_dict:
            count += count_dict[input_data]
            count_dict[input_data] += 1
        else:
            count_dict[input_data] = 1
    print(count)
if __name__ == '__main__':
    main()

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

nlist=[""]*N
d={}
for i in range(N):
    t=str(input())
    t=''.join(sorted(t))
    if d.get(t,None)==None:
        d[t]=1
    else:
        d[t]+=1 
ans=0


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

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

Solution (Python):
n=int(input())
dic={}
ans=0
for _ in range(n):
  s=input()
  s=str(sorted(s))
  if s not in dic:
    dic[s]=1
  else:
    ans+=dic[s]    
    dic[s]+=1
print(ans)

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

def sort_l(l):
    l.sort()
    return l
ws = list(map(sort_l, ws))
ws.sort()

i = 0
j = 0
r = 0
ans = 0
while(i<n-1):
    i += 1
    if ws[i] == ws[j]:
        r += 1
    else:
        ans += r * (r+1) // 2
        r = 0
        j = i
ans += r * (r+1) // 2

print(ans)

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

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

print(ans)

Solution (Python):
def find(strings):
    count={}
    ans=0
    for s in strings:
        s="".join(sorted([x for x in s]))
        
        if s in count:
            count[s]+=1
        else:
            count[s]=1
    for s in count:
        temp=count[s]
        ans+=temp*(temp-1)
    return ans//2
strings=[]
for _ in range(int(input())):
    
    strings+=[input()]
print(find(strings))

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

Solution (Python):
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

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

Solution (Python):
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
an=0
d={}

for i in c:
    if i in d:
        an += d[i]
        d[i]+=1
    else:
        d[i]=1

print(an)

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

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

lst = []
for _ in range(N):
    tmp = list(input())
    tmp.sort()
    lst.append(tmp)
lst.sort()
tmp = lst[0]
count = 1
ans = 0
for i in range(1, N):
    if tmp == lst[i]:
        count += 1
    else:
        ans = ans + (count * (count - 1))//2
        count = 1
        tmp = lst[i]
ans = ans + (count * (count - 1))//2
print (ans)

Solution (Python):
n = int(input())
d = {}
ans = 0
for st in range(n):
    s = ''.join(sorted(input()))
    if d.get(s) == None:
        d[s] = 1
    else:
        ans += d[s]
        d[s] += 1

print(ans)

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

Solution (Python):
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
counter = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in counter:
        ans += counter[a]
    counter[a] += 1
print(ans)

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

Solution (Python):
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    S[s] += 1
    ans += S[s]
print(ans)

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

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

Solution (Python):
n = int(input())
strdict = {}
count = 0
for i in range(n):
    sortedstr = "".join(sorted(str(input())))
    strdict.setdefault(sortedstr, 0)
    count += strdict[sortedstr]
    strdict[sortedstr] += 1
print(count)

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

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


n = int( input() )

dict = {}
for i in range( n ):
	sorted_input = "".join( sorted( list( input() ) ) )
	if dict.get( sorted_input ) == None:
		dict[ sorted_input ] = 1
	else :
		dict[ sorted_input ] += 1

count = 0
for eachValue in dict.values():
	if eachValue == 1 : continue
	count += cmb( eachValue, 2 )
print( count )

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

Solution (Python):
N=int(input())
dict={}
for _ in range(N):
  s=''.join(sorted(input()))
  dict[s]=dict.setdefault(s,0)+1
  
cnt=0
for c in dict.values():
  cnt+=(1+c-1)*(c-1)//2
  
print(cnt)

Solution (Python):
from collections import*;print(sum(c*~-c//2for c in Counter(map(tuple,map(sorted,open(0)))).values()))

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

def cmb(n,r):
	if n < r:return 0
	if r == 0 or n-r == 0:return 1
	r = min(n-r,r)
	up = reduce(mul, range(n, n-r, -1))
	down = reduce(mul, range(1,r+1))
	return up//down
    
l = []
for i in range(int(input())):
	l.append("".join(sorted(input())))
c = Counter(l)
ans = 0
for i in c.values():
	ans += cmb(i,2)
print(ans)

Solution (Python):
def C_GreenBin():
    from collections import Counter
    N = int(input())
    s = []
    for x in range(N):
        list_tmp = sorted(input())
        s.append("".join(list_tmp))
    result = 0
    s_tmp = Counter(s)
    for x in s_tmp.values():
        if x > 1:
            result += ((x - 1) * x) // 2
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

Solution (Python):
def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator

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

dic={}
for i in s:
	if i in dic:
		dic[i] +=1
	else:
		dic[i] = 1

result = 0
for j in dic.values():
	if j > 1:
		result += nCr(j,2)

print(result)

Solution (Python):
N = int(input())
strDict = {} 
for i in range(N):
    inStr = input()
    inList = []
    for j in range(len(inStr)):
        inList.append(inStr[j])
        inList.sort()
    sortStr = ''.join(inList)
    if sortStr in strDict:
        strDict[sortStr] = strDict[sortStr] + 1
    else:
        strDict[sortStr] = 1

anaglam = 0

for i in strDict.keys():
    anaglam = anaglam + strDict[i]*(strDict[i]-1)//2
    
print(anaglam)

Solution (Python):
import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    s = list(sys.stdin.readlines())
    new_s=sorted(s)
    char_list=[]
    dic ={}
    for i in s:
        i = i.replace('\n','')
        new_s=sorted(i)
        new_s = ''.join(new_s)
        char_list.append(new_s)
        if new_s not in dic:
            dic[new_s] = 1
        else:
            dic[new_s] += 1
    
    
    
    
    

    def combinations_count(n, r):
        if n - r < 0:
            return 0
        else:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    
    
    c=0
    
    for i in dic.values():
        c+=combinations_count(i, 2)
    print(c)

Solution (Python):
from collections import defaultdict

N = int(input())

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

line = defaultdict(int)

for anagram in s:
  a = sorted(anagram)
  line[''.join(a)] += 1

_sum = 0

for i in line:
  _sum += int((line[i] * (line[i] - 1)) / 2)

print(_sum)

Solution (Python):
N = int(input())
dic = {}
ans = 0
for i in range(N):
    s = [v for v in input()]
    s.sort()
    word = ''.join(s)    

    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1

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

print(ans)

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

Solution (Python):
N = int(input())
liss = {}
for i in range(N):
  s = input()
  a = "".join(sorted(s))
  if a in liss:
    liss[a] += 1
  else:
    liss[a] = 1

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(ans))

Solution (Python):
import collections as c
import math as m
print(sum([ m.factorial(n) // (m.factorial(n - 2) * 2) for n in c.Counter(map(lambda x:"".join(x),map(sorted,[input()for i in range(int(input()))]))).values() if n>1]))

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

dic = {}
for i in range(N):
    S.append(input())
    S[i] = sorted(S[i])
    S[i] = ''.join(S[i])
    if dic.setdefault(S[i], 0) > 0:
        count += dic[S[i]]
        dic[S[i]] += 1
    else:
        dic[S[i]] = 1
print(count)

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


def perm(n, r):
    return factorial(n) // factorial(n - r)


def comb(n, r):
    return perm(n, r) // factorial(r)


n = int(input())
D = defaultdict(lambda: 0)
for _ in range(n):
    D["".join(sorted(input()))] += 1
print(sum([comb(v, 2) for v in D.values() if v > 1] + [0]))

Solution (Python):
import sys
from collections import defaultdict as dd



def main():

	d = dd(int)
	for x in xrange(int(raw_input())):
		s = raw_input().rstrip()
		v = {i:0 for i in xrange(26)}
		for c in s:
			v[ord(c)-97]+= 1
		tu = ()
		for i in xrange(26):
			tu = tu + (v[i],)

		d[tu]+=	 1	

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

	print "%d"%ans

raw_input = sys.stdin.readline

if __name__ == '__main__':
	
	main()

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

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

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

print(ans)

Solution (Python):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)

Solution (Python):
from collections import Counter as C
n,*s=open(0)
print(sum(x*(x-1)//2 for x in C(tuple(sorted(i.strip()))for i in s).values()))

Solution (Python):
import collections
N = int(input())
s = [list(input()) for _ in range(N)]
mydict = {}
ans = 0
for i in s:
  a = str(sorted(i))
  if a in mydict:
    ans += mydict[a]
    mydict[a] += 1
  else:
    mydict.setdefault(a,1)
print(ans)

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

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    count = 0
    count_dict = {}

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in count_dict:
            count += count_dict[input_data]
            count_dict[input_data] += 1
        else:
            count_dict[input_data] = 1

    print(count)


if __name__ == '__main__' :
    main()

Solution (Python):
import math
import sys
import itertools
import queue
from fractions import gcd



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

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

from math import factorial
import collections

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    sl = []
    for _ in range(N):
        tmp = sorted(sys.stdin.readline().rstrip())
        sl.append(''.join(tmp))
    c = collections.Counter(sl)
    ans = 0
    for n in c.values():
        r = 2
        if n > 1:
            ans += factorial(n) // (factorial(n - r) * factorial(r))

    print(int(ans))

Solution (Python):
N = int(input())
ss = {}
ht = []
ans = 0

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

print(ans)