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 collections
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
B = collections.Counter(s)
print(sum(i*(i-1)//2 for i in B.values()))

Solution (Python):
import collections
N = int(input())
A = []
for i in range(N):
    s = sorted(input())
    A.append(str(s))
B = collections.Counter(A)
print(sum(i*(i-1)//2 for i in B.values()))

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

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


ans = 0

cnt = {}

for i in range(N):
    
    if s[i] in cnt:
        ans += cnt[s[i]]
        cnt[s[i]] += 1
    
    
    else:
        cnt[s[i]] = 1

print(ans)

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

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

listcount = collections.Counter(s)

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

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

ans=0
cnt={}

for i in range(N):
    if s[i] in cnt:
        ans+=cnt[s[i]]
        cnt[s[i]]+=1
    else:
        cnt[s[i]]=1
        
print(ans)

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

counter={}
ans=0
for i in range(n):
	ss = sorted(s[i])
	ss=("").join(ss)
	if ss not in counter:
		counter[ss]=0
	else:
		counter[ss]+=1
		ans+=counter[ss]

print(ans)

Solution (Python):
from collections import Counter
 
n = int(input())
s = [list(input()) for _ in range(n)]
for i in range(n):
    s[i].sort()
    s[i] = ''.join(s[i])
counter = Counter(s)

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

Solution (Python):
from collections import Counter

n = int(input())
s = [list(input()) for _ in range(n)]
for i in range(n):
    s[i].sort()
    s[i] = ''.join(s[i])
counter = Counter(s)
ans = 0
for val in counter.values():
    ans += val * (val - 1) // 2
print(ans)

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


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




s_dict = {}
for i in range(n):
	if s[i] in s_dict:
		s_dict[s[i]] += 1
	else:
		s_dict[s[i]] = 1
		
		
ans = 0

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

Solution (Python):

import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    counter = cl.Counter()
    for i in range(N):
        s = input()
        S = []

        for char in s:
            S.append(char)
        S.sort()
        
        s = "".join(S)
        counter.update({s:1})
    ans = 0

    for item, count in counter.items():
        ans += count * (count - 1) / 2
    print(int(ans))

main()

Solution (Python):
n = int(input())
S = [input() for _ in range(n)]
ans = 0
c = {}

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


print(ans)

Solution (Python):
import collections
N=int(input())
j=0
L=list()
R=list()
for i in range(N):
  S="".join(sorted(list(input())))
  L.append(S)
c = collections.Counter(L)
counts=c.values()
counts=list(counts)
A=[i*(i-1)//2 for i in counts]
print(sum(A))

Solution (Python):

from collections import defaultdict
from scipy.special import comb

n = int(input())
d = defaultdict(int)
for _ in range(n):
    d[''.join(sorted((list(input()))))] += 1

print(sum([comb(i, 2, exact=True) for i in d.values()]))

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

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

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

count = 0
for value in results.values():
  count += choose2(value)
print(count)

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

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()


def main():
    n=int(input())
    wlist=[]
    for _ in range(n):
        n=input()
        n=list(n)
        n.sort()
        n=''.join(n)
        wlist.append(n)
    cnt=Counter(wlist)
    ans=0
    for c in cnt.values():
        ans+=c*(c-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin

N = int(stdin.readline())

result = {}


def comb(n, r):
    up = 1
    down = 1
    for i in range(r):
        up *= n - i
        down *= i + 1
    return up // down


for _ in range(N):
    text = ''.join(sorted(stdin.readline().rstrip()))

    if text in result:
        result[text] += 1
    else:
        result[text] = 1

answer = 0
for v in result.values():
    answer += comb(v, 2)

print(answer)

Solution (Python):
import math 
import collections

N = int(input())
String = []
for i in range (0, N):
	S = str(input())
	S = sorted(S)
	V = str(S[0])
	for j in range (1, 10):
		V = V+str(S[j])
	String.append(V)
    
cnt = collections.Counter()
for word in String:
	cnt[word] += 1

V = cnt.most_common()

count = 0

for i in range (0, len(V)):
	count+=math.comb(V[i][1], 2)
    
print(count)

Solution (Python):
from collections import Counter
n = int(input())
sl = []
for i in range(n):
    s = list(input())
    s.sort()
    sl.append("".join(s))
d = Counter(sl)

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

ans = 0
val = d.values()
for i in val:
    if i > 1:
        ans += cul(i)
print(ans)

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


for i in range(n):
    line = input()
    line = sorted(line)
    line = str(line)
    if line not in anaglram_map:
        anaglram_map[line] = 1
    else:
        anaglram_map[line] += 1

couter = 0
for value in anaglram_map.values():
    if value >= 2:
        couter += value * (value - 1) // 2
print(couter)

Solution (Python):
import collections
n = int(input())
S = collections.defaultdict(int)
for _ in range(n):
    s = ''.join(sorted(input()))
    S[s] += 1
cnt = 0
for key,val in S.items():
    if val >1:
        cnt += val*(val-1)//2
print(cnt)

Solution (Python):
from collections import Counter
n=int(input())
s=[]
for _ in range(n):
    temp=sorted(list(input()))
    s.append("".join(temp))
s_count=Counter(s)
ans=0
for i in s_count:
    ans+=((s_count[i])*(s_count[i]-1))//2
print(ans)

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

Solution (Python):
dict={}
for _ in range(int(input())):
  s=''.join(sorted(input()))
  if s not in dict: dict[s]=1
  else: dict[s]+=1
print(sum([i*(i-1)//2 for i in dict.values()]))

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

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

Solution (Python):
n = int(input())
s = [list(input()) for _ in range(n)]
ans = 0
sd = dict([])

for i in s:
    key = ''.join(sorted(i))
    sd.setdefault(key, 0)
    sd[key] += 1
    
for v in sd.values():
    ans += v * (v - 1) // 2
print(ans)

Solution (Python):
import collections
n=int(input())
s=[]
for i in range(n):
  X=''
  Y=sorted(input())
  for i in range(10):
    X+=Y[i]
  s.append(X)
cnt=collections.Counter(s)
ans=0
for i in cnt.values():
  ans+=i*(i-1)//2
print(ans)

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
str_lis = ['']*N
ans_dic = defaultdict(int)
for i in range(N):
    tmp = S()
    tmp = tuple(sorted(tmp))
    ans_dic[tmp] += 1
ans = 0
for v in ans_dic.values():
    ans += comb(v, 2, exact=True)

print(ans)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

def getHyoujunn(s):
    tmp = sorted(collections.Counter(s).items(), key=lambda x: x[0])
    ret = []
    for k,v in tmp:
        for i in range(v):
            ret.append(k)
    return ''.join(ret)

n = ir()
s_list = []
for i in range(n):
    s = sr()
    s_list.append(getHyoujunn(s))
s_list.sort()
ans = []
pre = ''
add = 1
for c in s_list:
    if c == pre:
        add+=1
    else:
        ans.append(add)
        add=1
        pre = c
ans.append(add)
ansnum = 0
for num in ans:
    if num != 1:
        ansnum+=((num-1)*num)//2
print(ansnum)

Solution (Python):
n=int(input())
ans=0
lis=[]
def cnt(n):
  ret=0
  for i in range(1,n):
    ret+=i
  return ret
for i in range(n):
  lis.append(sorted(list(input())))
co=1
lis.sort()
bef=lis[0]

for i in lis[1:]:
  if bef!=i:
    ans+=cnt(co)
    co=1
    bef=i
  else:
    co+=1
ans+=cnt(co)
print(ans)

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

base = []
for i in s:
    base.append(''.join(sorted(i)))
    
base_dict = {}
for i in base:
    if i not in base_dict:
        base_dict[i] = 1
    else:
        base_dict[i] += 1

ans = 0
for key, value in base_dict.items():
    temp = 0
    if value != 1:
        temp = math.factorial(value) // (math.factorial(2) * math.factorial(value-2))
    ans += temp
    
print(ans)

Solution (Python):
import collections
N=int(input())
lis=[''.join(sorted(input(), key=str.upper)) for _ in range(N)]
v=collections.Counter(lis).values()
ans=sum(list(map(lambda x: x*(x-1)//2, v)))
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
C = Counter([''.join(sorted(input())) for _ in range(N)])
print(sum(list(map(lambda x: x[1] * (x[1] - 1) // 2, C.most_common()))))

Solution (Python):
def readinput():
    n=int(input())
    s=[]
    for _ in range(n):
        s.append(input())
    return n,s

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

def main(n,s):
    count={}
    for word in s:
        sword=''.join(sorted(word))
        if sword in count:
            count[sword]+=1
        else:
            count[sword]=1
    ans=0
    for k,v in count.items():
        if v>1:
            ans+=cmb(v,2)        

    return ans

if __name__=='__main__':
    n,s=readinput()
    ans=main(n,s)
    print(ans)

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

count = Counter(s)

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

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

count = Counter(s)

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

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

N = I()
s = [''.join(sorted(S())) for i in range(N)]

from collections import Counter

c = Counter(s)
ans = 0
for i in c.keys():
    ans += c[i]*(c[i]-1)//2

print(ans)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

N = I()
s = [''.join(sorted(S())) for i in range(N)]

from collections import Counter

c = Counter(s)
ans = 0
for i in c.keys():
    ans += c[i]*(c[i]-1)//2

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
slist = []
for _ in range(N):
    s = sorted(input())
    s = ''.join(s)
    slist.append(s)
slist = Counter(slist)
ans = 0
for i in slist.values():
    if i == 1:
        continue
    ans += (i*(i-1)+2)//2-1

print(ans)

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

for i in range(n):
    s = list(input())
    s.sort()
    s_s = ''.join(s)
    if s_s in S:
        ans += S[s_s]
        S[s_s] += 1
    else:
        S[s_s] = 1

print(ans)

Solution (Python):
from collections import defaultdict

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

SUM = 0
for val in count.values():
  if val > 1:SUM+=val*(val-1)//2
print(SUM)

Solution (Python):
def f(S):
    L=list(S)
    L.sort()
    return  "".join(L)

N=int(input())
D={}

for _ in range(N):
    T=f(input())
    if T in D:
        D[T]+=1
    else:
        D[T]=1

A=0
for k in D:
    A+=(D[k]*(D[k]-1))//2
print(A)

Solution (Python):
from collections import Counter,defaultdict

N=int(input())
count = defaultdict(int)
for i in range(N):
  s=Counter(list(input()))
  count[str(sorted(s.items()))] += 1

count = list(count.values())
SUM = 0
for c in count:
  if c>1:SUM += c*(c-1)//2
print(SUM)

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

counter = collections.Counter(lsS)
n=0
for i in counter.values():
    n+= (i*(i-1))//2
print(n)

Solution (Python):
from collections import defaultdict
from operator import mul
from functools import reduce
def C(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())
d = defaultdict(int)
for _ in range(N):
    s = input()
    s = tuple(sorted(list(s)))
    d[s] += 1
ans = 0
for v in d.values():
    if v > 1:
        ans += C(v, 2)
print(ans)

Solution (Python):



n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    s.sort()
    sl = ''.join(s)
    if d.get(sl) == None:
        d[sl] = 1
    else:
        d[sl] = d[sl] + 1

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

print(ans)

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

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

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

cnt=[]
i=0
for n in range(1,N):
    if s[n]==s[n-1]:
        i+=1
    else:
        cnt.append(i)
        i=0
if i!=0:
    cnt.append(i)

ans=0
for e in cnt:
    ans+=(e+1)*e//2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
c = Counter([''.join(sorted(input())) for i in range(n)])
 
ans = 0
for k, cnt in c.items():
    ans+=cnt*(cnt-1)//2
print(ans)

Solution (Python):
import math

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

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

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 1
  else:
    d[s] += 1

print(sum([comb(i, 2) for i in d.values()]))

Solution (Python):
from scipy.special import comb
N = int(input())
a = [input() for _ in range(N)]

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 1
  else:
    d[s] += 1

print(sum([comb(i, 2, exact=True) for i in d.values()]))

Solution (Python):
N = int(input())
Dic = {}
ans = 0
for _ in range(N):
  st = input()
  st=''.join(sorted(st))
  if st not in Dic:
    Dic[st]=0
  else:
    Dic[st]+=1
    ans+=Dic[st]
print(ans)

Solution (Python):
n=int(input())
s=[]
for i in range(n):
    a=input()
    b=[]
    for j in range(10):
        b.append(a[j])
    b.sort()
    c="".join(b)
    s.append(c)
s.sort()
ans=0
t=1
for i in range(1,n):
    if s[i]==s[i-1]:
        ans+=t
        t+=1
    else:
        t=1
print(ans)

Solution (Python):
N = 3
SRR = [
    "acornistnt",
    "peanutbomb",
    "constraint",
]

N = 5
SRR = [
    "abaaaaaaaa",
    "oneplustwo",
    "aaaaaaaaba",
    "twoplusone",
    "aaaabaaaaa",
]

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

for i in range(N):
    SRR.append(input())

def calculate(n,arr):
    dict = {}
    for i in range(n):
        str = "".join(sorted(list(arr[i])))
        if dict.get(str) == None:
            dict.__setitem__(str,1)
        else:
            dict.__setitem__(str,dict.get(str) + 1)

    result = 0

    for item in dict.values():
        if item > 1:
            result += (item * (item-1)) // 2

    print(result)


calculate(N, SRR)

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    import math
    N = int(input())
    Ss = [sorted([item for item in input()]) for _ in range(N)]
    
    sss = []
    for line in Ss:
        sss.append(''.join(line))
    line_cnt = collections.Counter(sss)

    cnt = 0
    for letter, num in line_cnt.most_common():
        if num >=2:
            cnt += math.comb(num, 2)

    print(cnt)
if __name__ == "__main__":
    resolve()

Solution (Python):






import collections





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





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

Solution (Python):
from collections import Counter

count_by_kw = Counter()

n=int(input())
l=[]
dict={}
ans=0
for x in range(n):
  a=sorted(input())
  b=''.join(a)
  if not b in dict:
    dict[b]=x
    l.append(b)
    count_by_kw[b]+=1
  else:
    d=count_by_kw[b]
    count_by_kw[b]+=1
    
for y in range(len(l)):
  r=l[y]
  w=count_by_kw[r]
  ans+=w*(w-1)//2

print(ans)

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

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

ans = 0

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

print(int(ans))

Solution (Python):
import sys
from io import StringIO
import unittest

from collections import Counter

def resolve():
    n = int(input())
    l = [input() for _ in range(n)]
    cnt = 0
    ee = dict()

    for ll in l:
        tmp = ''.join(sorted(ll))

        if tmp in ee.keys():
            cnt += ee[tmp]
            ee[tmp] += 1
        else:
            ee[tmp] = 1

    print(cnt)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
acornistnt
peanutbomb
constraint"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
oneplustwo
ninemodsix"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa"""
        output = """4"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    cnt = defaultdict(int)
    for _ in range(n):
        s = [x for x in input()]
        s.sort()
        s = ''.join(s)
        cnt[s] += 1
    ans = 0
    for k in cnt:
        n = cnt[k]
        ans += n * (n - 1) // 2
    print(ans)

t = 1

for case in range(1,t+1):
    ans = solve()


"""

abc

"""

Solution (Python):
import collections
N = int(input())
S = [sorted(input()) for i in range(N)]
SS = []
for i in S:
    SS.append("".join(i))
count = 0

c = collections.Counter(SS)

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

print(count)

Solution (Python):
from collections import Counter
n = int(input())
l = [''.join(sorted(input())) for i in range(n)]
    
c = Counter(l)
cnt = 0
for val in c.values():
    cnt += val * (val-1) //2

print(cnt)

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

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

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

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

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

Solution (Python):







__giturl__ = "$URL$"


from collections import defaultdict
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  S = [input()[:-1] for _ in range(N)]

  dic = defaultdict(int)

  for i in range(N):
    dic[''.join(sorted(S[i]))] += 1

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


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

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

from collections import Counter
n = int(input())
list_N = []
ans = 0

for _ in range(n):
    s = sorted(input())
    list_N.append("".join(s))

list_M = list(Counter(list_N).values())

for i in list_M:
    if i != 1:
        ans += cmb(i, 2)
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(int)
count = 0
for i in range(n):
    s = "".join(sorted(input()))
    count += d[s]
    d[s] += 1
print(count)

Solution (Python):
def main():
    n = int(input())
    slis = list()
    ans = 0
    sdic = {}
    for _ in range(n):
        s = input()
        s = ''.join(sorted(s))
        
        if s in sdic:
            tmp = sdic[s]
            ans += tmp
            sdic[s] += 1
        else:
            sdic[s] = 1
            
    print(ans)

    


if __name__ == "__main__":
    main()

Solution (Python):
import collections

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

for _ in range(n):
    a = sorted(input())
    l.append("".join(a))
    
ls = collections.Counter(l)
r = list(ls.values())

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

ans = 0
for i in r:
    ans += cul(i)
print(int(ans))

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

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
sdict = {}

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

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

Solution (Python):

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

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

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

mem = {}
ans = 0
for s in xs:
  if s in mem:
    ans += mem[s]
    mem[s] += 1
  else:
    mem[s] = 1
print(ans)

Solution (Python):
import sys



from collections import Counter



def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = []
    for i in range(N):
        s =list(input())
        s.sort()
        s = "".join(s)
        S.append(s)

    C  = Counter(S)
    ans =0
    for key,value in C.items():
        ans +=value*(value-1)/2

    print(int(ans))


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
b=[]
for _ in range(n):
  g=str(input())
  b.append(str(sorted(g)))
import collections
c = collections.Counter(b)

cnt=0
for i in c:
  cnt+=c[i]*(c[i]-1)/2
print(int(cnt))

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
d = defaultdict(int)
for i in [input() for j in range(n)]:
  d["".join(sorted(i))]+=1

from math import factorial as f

ans = 0
for i in d:
  if d[i]>1:
    ans+=f(d[i])//f(2)//f(d[i]-2)

print(ans)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

def comb(n,r):
  return math.factorial(n)//math.factorial(r)//math.factorial(max(1,n-r))

def con(t):
  ans = ""
  for i in t:
    ans+=i[0]+str(i[1])
  return ans

n = readInt()
d = defaultdict(int)
for i in [input() for i in range(n)]:
  t = defaultdict(int)
  for j in i:
    t[j]+=1
  d[con(sorted(t.items()))]+=1
ans = 0
for i in d:
  ans+=comb(d[i],2)

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())

S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  s = "".join(s)
  S[s] += 1
  
res = 0
for val in S.values():
  res += val * (val-1) // 2

print(res)

Solution (Python):
n=int(input())
d={}
ans=0
for _ in range(n):
  s=''.join(sorted(input()))
  if s in d.keys():d[s]+=1;ans+=d[s]
  else:d.setdefault(s,0)
print(ans)

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

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(int)
sens = set()
ans = 0
for _ in range(n):
  s = sorted(input())
  s = ''.join(s)
  if s in sens:
    d[s] += 1
    ans += d[s]
  else:
    sens.add(s)
print(ans)

Solution (Python):
from collections import defaultdict
import math
prm = [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]
alp = {chr(i):p for i,p in zip(range(97, 97+26),prm)}
n = int(input())
d = defaultdict(int)
nums = set([])
for _ in range(n):
  s = input()
  m = 1
  for l in s:
    m *= alp[l]
  d[m] += 1

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

ans = 0
for k in d.values():
  ans += comb(k,2)
print(ans)

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

Solution (Python):
import collections

N = int(input())
lan = ["".join(sorted(input())) for n in range(N)]

lans = collections.Counter(lan)

ans = 0
for si in set(lan):
    n = lans[si]
    ans += n * (n - 1) // 2
print(ans)