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())
s = [input() for i in range(n)]


s = list(map(list, s))

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())

import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Solution (Python):
n = int(input())
words = [sorted(input()) for _ in range(n)]
sorted_words = sorted(words)

result = 0
sorted_words_dup = sorted_words[:]
while sorted_words_dup:
    same_cnt = 1
    word = sorted_words_dup.pop()
    while 0 < len(sorted_words_dup) and sorted_words_dup[-1] == word:
        sorted_words_dup.pop()
        same_cnt += 1
    result += same_cnt*(same_cnt-1)//2

print(result)

Solution (Python):
import sys
import collections

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

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

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

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

Solution (Python):
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

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

print(cnt)

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

input_patterns = []

patterns = {}

def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

count = 0
for inp in input_patterns:
    key = sorted(inp)
    skey = ''

    for k in range(len(key)):
        skey = skey + key[k]

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

    if patterns[skey] > 1:
        count = count + patterns[skey] - 1
    
print('{}'.format(count))

Solution (Python):
import math
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

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

cnt = 0  
for i in c.values():
  if i >= 2:
    cnt += combinations_count(i, 2)

print(cnt)

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

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

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)

Solution (Python):
N = int(input())
inlist = []
for i in range(N):
  inputst = input()
  inputstlist = list(inputst)
  inputstlist.sort()
  inlist.append(inputstlist)
inlist.sort()
count=0
i=0
while i<N:
  skip=0
  for j in range(i+1,N):
    flag1=0
    for k in range(10):
      if inlist[i][k]!=inlist[j][k]:
        flag1=1
        break
    if flag1==0:
      count+=1
      skip+=1
    else:
      break
  if skip>=1:
    i=i+skip
    count+=int(((skip-1)+1)*(skip-1)/2)
  else:
    i+=1
print(count)

Solution (Python):
N=int(input())
S = []
for _ in range(N):
    tmp = []
    for s in input():
        tmp.append(s)
    tmp.sort()
    S.append("".join(tmp))
dic = {}
for s in S:
    if s not in dic:
        dic[s] = 0
    dic[s] += 1
ans = 0
for v in dic.values():
    ans += v * (v - 1) // 2
print(int(ans))

Solution (Python):
N=int(input())
S = []
for _ in range(N):
    tmp = []
    for s in input():
        tmp.append(s)
    tmp.sort()
    S.append("".join(tmp))
dic = {}
for s in S:
    if s not in dic:
        dic[s] = 0
    dic[s] += 1
ans = 0
import math
for v in dic.values():
    if v == 1:
        continue
    p = math.factorial(v)// (math.factorial(v - 2) * math.factorial(2))
    ans += p
print(ans)

Solution (Python):
import collections

N = int(input())

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

c = collections.Counter(sort)

res = 0
for key, value in c.items():
  res += value * (value - 1) // 2

print(res)

Solution (Python):
from collections import defaultdict
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
d = defaultdict(lambda: int())
to_str = "".join

for _ in range(N):
    row = to_str(sorted(input()))
    d[row] += 1

def solve():
    ans = 0
    for _, v in d.items():
        ans += v * (v - 1) // 2
    return ans

if __name__ == "__main__":
    print(solve())

Solution (Python):
from collections import defaultdict
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
d = defaultdict(lambda: int())
to_str = "".join

for _ in range(N):
    row = to_str(sorted(input()))
    d[row] += 1

def solve():
    ans = 0
    for _, v in d.items():
        ans += v * (v - 1) // 2
    return ans

if __name__ == "__main__":
    print(solve())

Solution (Python):
from collections import deque

n = int(input())
words = deque()
for i in range(n):
    words.append(input())

unique = {}
count = 0

for word in words:
    sorted_word = sorted(word)
    if ''.join(sorted_word) in unique:
        count += unique[''.join(sorted_word)]
        unique[''.join(sorted_word)] += 1
    else:
        unique[''.join(sorted_word)] = 1

print(count)

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

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

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

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

print(ans)

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

dic = {}
count = 0
for a in s:
  key = "".join(sorted(a))
  if key in dic:
    count += dic[key]
    dic[key] += 1
  else:
    dic[key] = 1

print(count)

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

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

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

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
s_lst = []
count_dict = {}

for _ in range(N):
  a = ''.join(sorted(stdin.readline().rstrip()))
  if a in count_dict:
    count_dict[a] += 1
  else:
    count_dict[a] = 1
  
result = sum([x * (x-1) / 2 for x in count_dict.values() if x > 1])
print(int(result))

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

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

print(count)

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


strings = [''.join(sorted(s)) for s in strings]
strings.sort()


hashMap = {}
for string in strings:
    if string not in hashMap:
        hashMap[str(string)] = 1
    else:
        hashMap[str(string)] += 1


sum = 0

for key in hashMap:
    v = hashMap[key]
    sum += v * (v - 1) / 2
print(int(sum))

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

result_num = 0
count_dict = {''.join(sorted(str(input()))): 1}

for i in range(n-1):
  word = ''.join(sorted(str(input())))

  if word in count_dict.keys():
    result_num += count_dict[word]
    count_dict[word] += 1
  else:
    count_dict[word] = 1

print(result_num)

Solution (Python):
import collections
print(sum((v - 1) * v // 2
          for v
          in collections.Counter(str(sorted(input()))
                                 for _ in range(int(input()))
                                 ).values()))

Solution (Python):
import collections

n = int(input())
counter = collections.Counter(str(sorted(input())) for _ in range(n))
combination_count = sum((v - 1) * v // 2 for v in counter.values())

print(combination_count)

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

Solution (Python):
import itertools
N = int(input().strip())
seq_list = [''.join(sorted(input().strip())) for _ in range(N)]
hash = {}
result = 0
for seq in seq_list:
  if seq in hash:
    result += hash[seq]
    hash[seq] += 1
  else:
    hash[seq] = 1
print(result)

Solution (Python):
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  count+=i*(i-1)/2
print(int(count))

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input().strip())
dic = {}
ans = 0

for i in range(n):
  s = ''.join(sorted(input().strip()))
  if s not in dic:
    dic[s] = 1
  else:
    dic[s] += 1
for v in dic.values():
  ans += v*(v-1)//2
print(ans)

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

Solution (Python):

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



d = dict()

ans = 0
for key in s:
    if key not in d:
        d[key] = 0
    else:
        ans += d[key]    
    d[key] += 1


print(ans)

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

for i in range(n):
  
  c = "".join(sorted(input()))
  v = s.get(c, 0)
  s[c] = v + 1

result = 0

for v in s.values():
  result += v * (v-1) / 2

print(int(result))

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
s_list=[]
for i in range(n):
    s=input().rstrip()
    s=list(s)
    s.sort()
    s_list.append(str(s))
s_list.sort()
pre='X'
count=0
ans=0
for i in s_list:
    if i==pre:
        count+=1
    else:
        ans+=count*(count+1)//2
        count=0
    pre=i
ans+=count*(count+1)//2
print(ans)

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


i = 0
while (i < N):
	current = s[i]
	same = 1
	while(i < N-1):
		if(s[i+1] == current):
			i += 1
			same += 1
		else:
			break

	ans += same * (same - 1)//2
	
	i += 1

print(ans)

Solution (Python):
s = []
ans = 0
count = 1

n = int(input())
for i in range(n):
	s_i = sorted(input())
	s.append("".join(s_i))
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(ans)

Solution (Python):

import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

def to_int():
    s = sorted(input())
    res = 0
    for c in s:
        c = ord(c)
        res = (res * 1337 + c) % 10**19+7
    return res

n=getint()
values = [to_int() for _ in range(n)]

cnt = collections.Counter()

for v in values:
    cnt[v] += 1

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

print(res)

Solution (Python):
import math
from itertools import accumulate
from collections import Counter
import itertools
import functools


N = int(input())

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


strings = [''.join(sorted(i)) for i in strings]
c = Counter(strings)
count = 0
for i in c.values():
    if i > 1:
        count += (i * (i - 1)) / 2
print(int(count))

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

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

s = sorted(s)

tmp_count = 1
count = 0
for i in range(0, len(s)-1):
    if s[i] == s[i+1]:
        tmp_count += 1
    else:
        count += tmp_count * (tmp_count - 1) // 2
        tmp_count = 1
count += tmp_count * (tmp_count - 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 += int(n * (n - 1) / 2)
print(ans)

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=['']*n

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

c=0
t=0
for i in range(n-1):
  if s[i]==s[i+1]:
    c+=1
  elif c!=0:
    t+=(c+1)*c//2
    c=0
if c!=0:
  t+=(c+1)*c//2

print(t)

Solution (Python):


def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 1

for key in words.keys():
    words[key] = max(words[key]*(words[key]-1)//2, 0)

print(sum(words.values()))

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

for i in range(n):
    if str_list[i] in str_dic:
        str_dic[str_list[i]] += 1
        ans += str_dic[str_list[i]]
    else:
        str_dic[str_list[i]] = 0

print(int(ans))

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

for i in range(n):
    if str_list[i] in str_dic:
        str_dic[str_list[i]] += 1
    else:
        str_dic[str_list[i]] = 0

for v in str_dic.values():
    ans += v*(v+1)/2

print(int(ans))

Solution (Python):
a = int(input())
t = [input() for i in range(a)]
cnt = 0
dict = {}
for i in range(a):
    src = "".join(sorted(t[i]))
    if src in dict.keys():
        dict[src] += 1
    else:
        dict[src] = 0
ans = 0
for a in dict.values():
    ans += a*(a+1)/2
print(int(ans))

Solution (Python):
from collections import Counter

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

sorted_S =  [''.join(sorted(s)) for s in S]
c = Counter(sorted_S)

print(sum([n * (n-1)//2 for n in  list(c.values())]))

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

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

for i in range(n):
	x = list(input())
	x.sort()
	n = ''.join(x)
	s_lis.append(n)

z = collections.Counter(s_lis)

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

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

for i in range(n):
    a[i].sort()

a.sort()

ans = 0
same_n = 0
for i in range(1, n):
    if a[i] != a[i - 1]:
        same_n = 0
    else:
        same_n += 1
    ans += same_n

print(ans)

Solution (Python):
from collections import Counter

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

sorted_S =  [''.join(sorted(s)) for s in S]
c = Counter(sorted_S)

print(sum([n * (n-1)//2 for n in  list(c.values())]))

Solution (Python):
N = int(input())
S=[]
for n in range(N):
    S.append(input())
Sdict = {}
for s in S:
    lists = list(s)
    listss = sorted(lists)
    listsss = ''.join(listss)
    if Sdict.get(listsss) == None:
        Sdict[listsss] = 1
    else:
        Sdict[listsss] += 1
count = 0
for value in Sdict.values():
    count += int(value*(value-1)/2)
print(count)

Solution (Python):

N=int(input())

dict={}

ans=0    
for i in range(N):
  tmp = "".join(sorted(input()))
  if tmp not in dict:
    dict[tmp]=0
  else:
    dict[tmp]+=1
    ans+=dict[tmp]
    
print(ans)

Solution (Python):


import copy
import sys
import math

n = int(input())
fuga = [0 for i in range(10)]

wordlist={}
for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		fuga[j]=tmp[j]
	fuga.sort()
	hoge=fuga[0]+fuga[1]+fuga[2]+fuga[3]+fuga[4]+fuga[5]+fuga[6]+fuga[7]+fuga[8]+fuga[9]

	if(hoge in wordlist):
		wordlist[hoge]+=1
	else:
		wordlist[hoge]=1




total=0
for i in wordlist:
	t=wordlist[i]
	if(t>=2):
		total+=t*(t-1)//2


print(total)

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

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

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

s.sort()

ans = 0
count = 0

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

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

print(ans)

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

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

s.sort()

ans = 0
count = 0

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

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

print(ans)

Solution (Python):
n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
d = {}
for i in S:
    d.setdefault(i, 0)
    d[i] += 1
ans = 0
for value in d.values():
    ans += value * (value - 1) // 2
print(ans)

Solution (Python):
from collections import Counter

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

prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
         53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]

d = {}
for i in range(26):
    d[chr(ord('a')+i)] = prime[i]

N = int(input())
L = []
nums = [input()[:-1] for _ in range(N)]
for n in nums:
    tmp = 1
    for c in n:
        tmp *= d[c]
    L.append(tmp)

L = Counter(L)

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

Solution (Python):
from collections import Counter

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

prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
         53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]

d = {}
for i in range(26):
    d[chr(ord('a')+i)] = prime[i]

N = int(input())
L = []
nums = [input()[:-1] for _ in range(N)]
for n in nums:
    tmp = 1
    for c in n:
        tmp *= d[c]
    L.append(tmp)

L = Counter(L)

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

Solution (Python):
n = int(input())
map = {}
for i in range(n):
  str = ''.join(sorted(input()))
  if str in map:
    map[str] += 1
  else:
    map[str] = 1

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

print(ans)

Solution (Python):
n = int(input())
S = ["".join(list(sorted(input()))) for _ in range(n)]
d = {}
for i in S:
    d.setdefault(i, 0)
    d[i] += 1
ans = 0
for value in d.values():
    ans += value * (value - 1) / 2
print(int(ans))

Solution (Python):
N = int(input())
S = [list(input()) for _ in range(N)]
cnt = 0
dic = {}
for s in S:
    s.sort()
    s_ = "".join(s)
    if s_ in dic.keys():
        cnt += dic[s_]
        dic[s_] += 1
    else:
        dic[s_] = 1
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
word_l = list()
for _ in range(n):
  word = ''.join(sorted(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(map(lambda x: sum(range(x)), word_counter.values()))))

Solution (Python):
n=int(input())
arr=[]
dict1={}
for i in range(n):
	arrcount=[0]*26
	s=str(input())
	for i in s:
		arrcount[ord(i)-97]+=1
	s1='abcdefghijklmnopqrstuvwxyz'
	s2=''
	for i in range(26):
		s2+=s1[i]*arrcount[i]
	try:
		dict1[s2]+=1
	except:
		KeyError
		dict1[s2]=1

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

Solution (Python):


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

output = 0
dic = dict()
for i in range(N):
    tmp = ''.join(sorted(s[i]))
    if tmp not in dic:
        dic[tmp] = 1
    else:
        output += dic[tmp]
        dic[tmp] += 1

print(output)

Solution (Python):
from collections import Counter

n = int(input())
array = sorted(["".join(sorted(input())) for x in range(n)])
counter = Counter(array)

res = 0
for key, value in counter.items():
    res += value*(value-1)//2
print(res)

Solution (Python):
import collections  

n = int(input())

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

cnt = 0
for (c, m) in collections.Counter(s).items():
    cnt += m * (m - 1) // 2
    
print(cnt)

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

d_word={}
count=0

for _ in range(N):
  word = "".join(sorted(input()))
  if word not in d_word:
    d_word[word]=0
  else:
    d_word[word]+=1
    count+=d_word[word]

print(count)

Solution (Python):
N = int(input())
arr = [[str(i) for i in input()] for _ in range(N)]

arr_sort = [ "".join(sorted([i for i in l])) for l in arr]

dict = {}
for i in arr_sort:
    if i in dict.keys():
        dict[i] += 1
    else:
        dict[i] = 0
        dict[i] += 1
        
ans = 0
for v in dict.values():
    ans += v * (v-1) / 2
    
print(int(ans))

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

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


s=[]
d={}
total=0
for i in range(n):
  s.append(list(input()))
  s[i].sort()
  ssort=''.join(s[i])
  if ssort in d:
    total += d[ssort]
    d[ssort]+=1
  
  else:
    d[ssort]=1

print(total)

Solution (Python):
N = int(input())
ans = 0
ana_dict = {}
for i in range(N):
    str = input()
    str= ''.join(sorted(str))
    if str in ana_dict:
        ans+=ana_dict[str]
        ana_dict[str]+=1
    else:
        ana_dict.setdefault(str, 1)
print(ans)

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


def nC2(num):
    return int(num * (num - 1) / 2)


count_dict = {}

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

L = list(count_dict.values())

for l in L:
    ans += nC2(l)
print(ans)

Solution (Python):
n=int(input())
s_list=[''.join(sorted(input())) for i in range(n)]
c = 0
words = {}
for s in s_list:
  time = words.get(s,0)
  c += time
  words[s] = time + 1
print(c)

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


for i in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    count += dic.get(s_sorted, 0)
    dic[s_sorted] = dic.get(s_sorted, 0) + 1

print(count)

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

cnt = 0
dic = {}

for i in lst:
    if i in dic:
        cnt += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1

print(cnt)

Solution (Python):
n = int(input())
words = []
for i in range(n):
  s = input()
  a = [s[i] for i in range (len(s))]
  a.sort()
  words.append(a)
words.sort()

s = 0 
v = 0 

old = False
for i in range(1,n):
  if words[i]==words[i-1] and (not old):
    s += 1
    v = 2
    old = True
  elif words[i]==words[i-1] and old:
    s += v
    v += 1
  else:
    old = False

print(s)

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""

def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
a = []
for i in range(n):
    b = input()
    c = [b[i] for i in range(len(b))]
    c.sort()
    a.append(''.join(c))
a.sort()
ans = 0
current = a[0]
count = 1
for i in range(1,n):
    if a[i] != current:
        ans+=(count*(count-1)//2)
        current = a[i]
        count = 1
    else:count+=1
ans+=(count*(count-1)//2)
current = 1
print(ans)

Solution (Python):
n=int(input())
ss=[input() for i in range(n)]
d={}
ans=0
for i in ss:
    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):
N=int(input())

count=0
dic={}
for i in range(N):
  s=input()
  sorted_s="".join(sorted(s))
  count += dic.get(sorted_s, 0)
  dic[sorted_s] = dic.get(sorted_s, 0) + 1
print(count)

Solution (Python):
n = int(input())
l = [input() for _ in range(n)]
l = [sorted([j for j in i]) for i in l]
l = ["".join(i) for i in l]
al = list(set(l))
ans_dict = {}
ans = 0
for i in l:
    if i in ans_dict:
        
        ans += ans_dict[i]
        ans_dict[i]+=1
    else:
        ans_dict[i] = 1

print(ans)

Solution (Python):
from collections import Counter

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

for i in range(N):
    S.append(''.join(sorted(input())))

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

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())
t=tuple([''.join(sorted(list(input()))) for _ in range(N)])
Dic = {}
ans = 0
for i in range(N):
    if t[i] in Dic:
        Dic[t[i]]+=1
    else:
        Dic[t[i]]=1
for k in tuple(Dic.keys()):
    if Dic[k]==1:
        pass
    else:
        ans+=cmb(Dic[k], 2)
print(int(ans))

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

sa = sn[0]
cnt = 0
n = 1
for sb in sn[1:]:
  if sb == sa:
    n += 1
  else:
    cnt += (n * (n-1) // 2)
    n = 1
    sa = sb
cnt += (n * (n-1) // 2)
print(cnt)

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

dct = {}
ans = 0

for i in range(n):
    item = s[i]
    if item in dct:
        dct[item] += 1
    else:
        dct.setdefault(item, 0)
    num = dct[item]
    ans += num

print(ans)

Solution (Python):

"""解説PDF
s1 = "abaaa" をソートして "aaaab" を得る。
s2 = "dddcc" をソートして "ccddd" を得る。
s3 = "baaaa" をソートして "aaaab" を得る。これはすでに一回現れているので答えに1を足す。
s4 = "cdddc" をソートして "ccddd" を得る。これはすでに一回現れているので答えに1を足す。
s5 = "aaaab" をソートして "aaaab" を得る。これはすでに二回現れているので答えに2を足す。

というふうにやる。

「これはすでにK回現れているので」は、ハッシュテーブルでやればよい

"""
def solve():
    N = int(input())
    d = {}
    for i in range(N):
        s = "".join(sorted(input()))
        if not s in d:
            d[s] = 0
        d[s] += 1

    ans = 0
    for s, value in d.items():
        if value >= 2:
            
            ans += (value-1+1)*(value-1)/2
    print(int(ans))


if __name__ == "__main__":
    solve()

Solution (Python):
def resolve():
    n = int(input())
    dic = {}
    count = 0
    for i in range(n):
        s = input()
        sorted_s = "".join(sorted(s))
        count += dic.get(sorted_s, 0)
        dic[sorted_s] = dic.get(sorted_s, 0) + 1

    print(int(count))
resolve()

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

print(cnt)

Solution (Python):
from collections import defaultdict

dic = defaultdict(int)

N = int(input())

for _ in range(N):
    dic[tuple(sorted(input()))] += 1
    
print(sum(map(lambda x: x * (x - 1) // 2, dic.values())))

Solution (Python):
from collections import Counter as ct
n = int(input())
ans = 0
words = [ct(input()) for _ in range(n)]
words = ct([tuple(sorted([(x, y) for x, y in z.items()])) for z in words])

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

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

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

from collections import Counter

c = Counter(l)

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

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