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 = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 1
print(ans)

Solution (Python):
n = (int)(input())
s = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 1
print(ans)

Solution (Python):
N = int(input())
a = [''.join(sorted(list(input()))) for _ in range(N)]
import collections
c = collections.Counter(a)
c_ls = list(c.values())
ans = 0
for i in range(len(c_ls)):
  ans += c_ls[i] * (c_ls[i]-1)//2
print(ans)

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

Solution (Python):
def green_bin(n, sli):

    ans = 0
    count = {}

    for i in sli:
        i.sort()
        if ''.join(i) in count:
            ans += count[''.join(i)]
            count[''.join(i)] += 1

        else:
            count[''.join(i)] = 1

    return ans

def main():
    n = int(input())
    sli = [list(str(input()))for i in range(n)]
    print(green_bin(n, sli))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import defaultdict

N = int(input())
s = defaultdict(lambda:0)
count=0

for i in range(N):
  a = "".join(sorted(input()))
  s[a] +=1
  
  if s[a] >1:
    count += s[a]-1
print(count)

Solution (Python):
import sys, collections
n = int(input())
uq = ["".join(sorted(x.rstrip())) for x in sys.stdin.readlines()]
chk = collections.Counter(uq)
ans = 0
for x in chk:
    if chk[x] != 1:
        ans += chk[x]*(chk[x]-1)//2
print(ans)

Solution (Python):
from collections import Counter


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


N = int(input())
counter = Counter()

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

print(sum([nc2(count) for count in counter.values() if count > 1]))

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


def nc2(n):
    return factorial(n) // 2 // factorial(n - 2)


N = int(input())
counter = Counter()

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

print(sum([nc2(count) for count in counter.values() if count > 1]))

Solution (Python):
N = int(input())
S = []
Y = {}
c = 0
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  u = t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+t[7]+t[8]+t[9]
  if u not in Y:
    Y[u] = 1
  else :
    c += Y[u]
    Y[u] += 1
    


print(c)

Solution (Python):
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
s.sort()
ans = 0
now = ''
cnt = 0
for si in s:
    if si == now:
        ans += cnt
        cnt += 1
    else:
        now = si
        cnt = 1
print(ans)

Solution (Python):
n = int(input())
sl = [input() for nesya in range(n)]
sm = []
for s in sl:
  t = list(s)
  t.sort()
  sm.append(''.join(t))
d = dict()
for m in sm:
  if m in d:
    d[m] += 1
  else:
    d[m] = 1
c = 0
for v in d.values():
  c += v*(v-1)//2
print(c)

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

from collections import Counter
counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Solution (Python):
n = int(input())
d = {}
for i in range(n):
    s = sorted(list(input()))   
    s = ''.join(s)
    d[s] = d.get(s, 0) + 1

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

print(cnt)

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

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

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

print(sum(t[k]*(t[k]-1)//2 for k in t))

Solution (Python):
n = int(input())
d = {}
for i in range(n):
    s = sorted(list(input()))   
    s = ''.join(s)
    d[s] = d.get(s, 0) + 1

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

print(cnt)

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
cnt = 0
for k in s_sorted:
    if k in s_dict:
        cnt += s_dict[k]
        s_dict[k] += 1
    else:
        s_dict[k] = 1






print(cnt)

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
for k in s_sorted:
    if k in s_dict:
        s_dict[k] += 1
    else:
        s_dict[k] = 1




cnt = sum([sum(range(s_dict[k])) for k in s_dict])

print(cnt)

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
for k in s_sorted:
    if k in s_dict:
        s_dict[k] += 1
    else:
        s_dict[k] = 1

cnt = 0
for k in s_dict:
    cnt += sum(range(s_dict[k]))

print(cnt)

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

s.sort()
ans = 0
lcnt = 1
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        lcnt += 1
    else:
        ans += lcnt * (lcnt-1)//2
        lcnt=1

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

print(ans)

Solution (Python):
def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    ans = 0
    chk = {}
    for tmp in s:
        d1 = "".join(sorted(list(tmp)))
        if d1 in chk.keys():
            ans += chk[d1]
            chk[d1] += 1
        else:
            chk[d1] = 1
    print(ans)


resolve()

Solution (Python):
import sys
from collections import defaultdict

n, *lst = sys.stdin.read().split()
n = int(n)
c = defaultdict(int)
for i in lst:
  tmpi = ''.join(sorted(i))
  c[tmpi] += 1
res = 0
for key in c:
  res += c[key] * (c[key] - 1) // 2
print(res)

Solution (Python):
import math

n = int(input())


def cho(i):
    return (i * (i - 1)) // 2


d = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

_ans = 0
for k, v in d.items():
    if v == 0: continue
    _ans += cho(v + 1)

print(_ans)

Solution (Python):
from collections import Counter

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

counter = 0
for v in Counter(t).values():
    if v > 1:
        counter += (v*(v-1))//2

print(counter)

Solution (Python):
import collections

dic = collections.defaultdict(lambda:0)

N = int(input())
ans = 0
for _ in range(N):
  s = "".join(sorted(input()))
  dic[s] += 1
  if dic[s] > 1:
    ans += dic[s] - 1

print(ans)

Solution (Python):
import collections
n = int(input())
s = [0] * n
c = [0] * n

count = 0
for i in range(n):
    s[i] = input()
    c[i] = ''.join(sorted(s[i]))
for i in collections.Counter(c).values():
    count += i*(i-1)//2
print(count)

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


s = [0] * n
for i in range(n):
    IN = input()
    inSort = sorted(IN)
    
    s[i] = ''.join(inSort)

count = Counter(s)
most = count.most_common()

inSet = set(s)
loop = list(inSet)


ans = 0
for i in most:
    
    
    aa = i[1]
    if (aa == 1):
        pass
    else:
        ans += aa * (aa - 1) / 2


print(int(ans))

Solution (Python):
from collections import Counter
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
lcnt = Counter(l)
ls = set(l)
ans = 0
for i in ls:
    
    ans += (lcnt[i]*(lcnt[i]-1))//2
print(ans)

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

Solution (Python):
from collections import Counter

n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
sc = Counter(s)
ss = set(s)
ans = 0

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

print(ans)

Solution (Python):
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
	s=list(input())
	s.sort()
	s=''.join(s)
	dic[s]+=1
ans=0
for (k,v) in dic.items():
	ans += v*(v-1)//2
print(ans)

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

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

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
s.sort()
ans,c = 0,0
for i in range(1,n):
    if s[i]==s[i-1]:
        c+=1
        ans+=c
    else:
        c = 0
print(ans)

Solution (Python):
n = int(input())
li = []
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[i] == li[i+1]:
        f += 1
    else:
        count += (f*(f-1))//2
        f = 1
count += (f*(f-1))//2
print(count)

Solution (Python):


from math import factorial
 
def unique(w):
    d = {}
    for c in w:
        if c in d.keys():
            d[c] += 1
        else:
            d.setdefault(c, 1)
    return list(d.values())
 
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()

s = [''.join(sorted(list(t))) for t in s]
values = unique(s)
count = 0
for i in values:
    if i > 1:
        count += factorial(i) // factorial(2) // factorial(i - 2)
print(count)

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

Solution (Python):
import collections

n = int(input())

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

l_2 = collections.Counter(l)
ans = 0
for j in l_2.values():
    ans += int((j*(j-1))/2)

print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
d = defaultdict(int)

for _ in range(N):
    s = input()
    k = sorted(s)
    d[''.join(k)] += 1

ans = 0    

for k, v in d.items():
    if v > 1:
        ans += v * (v - 1) // 2

print(ans)

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

Solution (Python):
n = int(input())
arr = []
for i in range(n):
    s = list(str(input()))
    s.sort()
    arr.append(s)
arr.sort()
ans = 0
count = 1
for i in range(1, n):
    if arr[i] == arr[i - 1]:
        count += 1
    else:
        ans += count * (count - 1) // 2
        count = 1
    if i == n - 1:
        ans += count * (count - 1) // 2
print(ans)

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


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

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

Solution (Python):
import collections

n = int(input())
s = list(''.join(sorted(input())) for i in range(n))
c = collections.Counter(s)
num = 0

for i in set(s):
  n = c[i]
  num += (n * (n - 1)//2)
print(num)

Solution (Python):
n = int(input())
si = [0]*n
for i in range(n):
    si[i] = input()

listarr = []
for s in si:
    arr = list(s)
    arr.sort()
    arr = tuple(arr
    )
    listarr.append(arr)
from collections import Counter

cont = Counter(listarr)
ans = 0
for i in cont.values():
    if i >= 2:
        num = (i*(i-1))//2
        ans += num

print(ans)

Solution (Python):

from collections import Counter

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

for i in range(N):
    Temp_Word=''.join(sorted(input()))
    Word_List.append(Temp_Word)

Word_Count=Counter(Word_List)
Word_PairCount_List = []

for i in Word_Count.values():
    if i > 1 :
        Word_PairCount_List.extend(range(i))

print(sum(Word_PairCount_List))

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

Solution (Python):
from collections import Counter
import math
def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n = int(input())
S =[input() for _ in range(n)]
S =[''.join(sorted(s)) for s in S]
ans = 0
c = Counter(S)
for i in c.values():
    if i >= 2:
        ans += combination(i, 2)
print(ans)

Solution (Python):
import itertools
import math
import fractions
import functools
n = int(input())
s = []
for i in range(n):
    string = sorted(input())
    s.append(''.join(string))

hist = {}
for i in range(n):
    current = hist.get(s[i],0)
    hist[s[i]] = current + 1

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

print(count)

Solution (Python):
import sys
readline = sys.stdin.readline
from collections import defaultdict
dic = defaultdict(int)

N = int(readline())
for i in range(N):
  s = readline().rstrip()
  dic["".join(sorted(s))] += 1

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

Solution (Python):
n=int(input())
mojilist=[]
for i in range(n):
	tmps=sorted(input())
	mojilist.append("".join(tmps))

mojilist.sort()
tmp=""
count=1
sum=0
for moji in mojilist:
	if moji == tmp:
		count += 1
	else:
		sum += count*(count-1)//2
		count=1
		tmp=moji

sum += count*(count-1)//2
print(sum)

Solution (Python):
from scipy.special import comb

N = int(input())
sdict = {}
for i in range(N):
    inp = ''.join(sorted(list(input())))
    if inp not in sdict:
        sdict.update({inp:1})
    else:
        sdict[inp] += 1

ans = 0
for key in sdict:
    ans += comb(sdict[key], 2 , exact=True)

print(ans)

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

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

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

Solution (Python):
import collections

N = int(input())
S = [input() for _ in range(N)]
S = [''.join(sorted(x)) for x in S]
S = collections.Counter(S)

ans = [x*(x-1)//2 for x in S.values()]
print(sum(ans))

Solution (Python):
import itertools
import collections
N = int(input())
S = [[str(x) for x in input()] for _ in range(N)]
S = [''.join(sorted(x)) for x in S]

cnt=0
reg = collections.defaultdict(int)
for s in S:
    reg[s] += 1
    if reg[s] > 1:
        cnt += reg[s] - 1
print(cnt)

Solution (Python):
n = int(input())
Dict = {}
ans = 0
tmp_list = []
for i in range(n):
    tmp = list(input())
    tmp_list.append(tmp)
tmp_list.reverse()
for i in range(n):
    tmp = tmp_list[i]
    tmp = sorted(tmp)
    tmp = ''.join(tmp)
    if tmp not in Dict.keys():
        Dict[tmp] = 1
    else:
        ans += Dict[tmp]
        Dict[tmp] += 1
print(ans)

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

res =0
cd = {}

for i in range(N):
    w = "".join(sorted(input()))
    if cd.get(w, 0):
        res += cd[w]
        cd[w] += 1
    else:
        cd[w] = 1
print(res)

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

Solution (Python):
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
counts = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in counts:
        counts[s] += 1
    else:
        counts[s] = 1

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

Solution (Python):
import sys
import math
import bisect

def main():
    d = dict()
    for _ in range(int(input())):
        s = ''.join(sorted(input()))
        if s not in d:
            d[s] = 0
        d[s] += 1
    ans = 0
    A = list(d.values())
    for a in A:
        val = a * (a - 1) // 2
        ans += val
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict
import math

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

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    if v > 1:
        SUM += combinations_count(v,2)

print(SUM)

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

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

N=int(input())
mem={}
for i in range(N):
    s=list(input())
    s.sort()
    s=''.join(s)
    if s in mem: mem[s]+=1
    else: mem[s]=0
    count=0
for i in mem.values():
    if i!=0: count += combination(i+1,2)
print(count)

Solution (Python):
n = int(input())
lst = []
for i in range(n):
  s = list(input())
  s = sorted(s)
  lst.append(s)
lst = sorted(lst)
lst.append(["dummy"])

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

Solution (Python):
n = int(input())
Dict = {}
ans = 0
tmp_list = []
for i in range(n):
    tmp = list(input())
    tmp_list.append(tmp)
tmp_list.reverse()
for i in range(n):
    tmp = tmp_list[i]
    tmp = sorted(tmp)
    tmp = ''.join(tmp)
    if tmp not in Dict.keys():
        Dict[tmp] = 1
    else:
        ans += Dict[tmp]
        Dict[tmp] += 1


print(ans)

Solution (Python):
from math import factorial

def unique(w):
    d = {}
    for c in w:
        if c in d.keys():
            d[c] += 1
        else:
            d.setdefault(c, 1)
    return list(d.values())

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

s = [''.join(sorted(list(t))) for t in s]
values = unique(s)
count = 0
for i in values:
    if i > 1:
        count += factorial(i) // factorial(2) // factorial(i - 2)
print(count)

Solution (Python):
from collections import Counter


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

cnt = Counter(S)
 
ans = 0
for num in cnt.values():
    ans += num*(num-1)//2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
S = [str(sorted(input())) for _ in range(n)]

print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

Solution (Python):
from collections import Counter

N = int(input())
Sss = [''.join(sorted(input().rstrip())) for _ in range(N)]

cnt = Counter(Sss)


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

Solution (Python):

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

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

Solution (Python):
import collections
n = int(input())
S = ["".join(sorted(input())) for _ in range(n)]
C = collections.Counter(S)
ans = [(v * (v - 1) // 2) for v in C.values() if v >= 2]
print(sum(ans))

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

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

found = {}
cnt = 0
for s_i in s:
    if s_i in found:
        found[ s_i ] = found[ s_i ] + 1
    else:
        found[ s_i ] = 0

for key in found:
    c = found[key]
    cnt = cnt + c * ( c + 1 ) // 2

print( cnt )

Solution (Python):
from collections import Counter

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

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

print(ans)

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


def input1():
	return int(input())


def input2():
	return map(int,input().split())


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

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp
		


n=input1()
s=[]
for i in range(n):
	s.append(str(input()))
str_dict={"".join(sorted(s[0])):0}
count=0
for i in range(1,n):
	now_d="".join(sorted(s[i]))
	if now_d in str_dict:
		str_dict[now_d]+=1
		count+=str_dict[now_d]
	else:
		str_dict[now_d]=0
print(count)

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

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

Solution (Python):
from collections import Counter

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

ans = 0

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

Solution (Python):
n = int(input())
ss = []
for _ in range(n):
    ss.append(sorted(input().strip()))
ss.sort()
now = ss[0]
ans = 0
cnt = 1
for i in range(1, n):
    if ss[i] == now:
        cnt += 1
    else:
        if cnt != 1:
            ans += cnt * (cnt - 1) // 2
        now = ss[i]
        cnt = 1
if cnt != 1:
    ans += cnt * (cnt - 1) // 2
print(ans)

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

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

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

ans = 0
cnt = 1 

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

Solution (Python):


from collections import Counter

N = int(input())
S = [str(input()) for _ in range(N)]
for i in range(N):
    S[i] = ''.join(sorted([s for s in S[i]]))
counter = Counter(S)
ans = 0
for i in counter.values():
    tmp = 0
    for j in range(1, i):
        tmp += j
    ans += tmp

print(ans)

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

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
T = [S() for _ in range(n)]
S = []
for t in T:
    S.append("".join(sorted(t)))

ans = 0
tmp = Counter(S)
for k, v in tmp.items():
    if v > 1:
        ans += int(v*(v-1)//2)

print(ans)

Solution (Python):
n = int(input())
cnt = 0
A = []
for _ in range(n):
    t = sorted(input())
    t = "".join(t)
    A.append(t)

import collections
C = collections.Counter(A)
lC = list(C.values())
for i in lC:
    cnt += i * (i-1) // 2
print(cnt)

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

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

Solution (Python):

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

for i in range(n):
    s  = input()
    l = list(s)
    l.sort()
    sort_s = "".join(l)
    buf.append(sort_s)

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
d = defaultdict(int)
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = tuple(tmp)
    d[tmp] += 1
res = 0
for key in list(d):
    v = d[key]
    res += v*(v-1)//2
print(res)

Solution (Python):

import sys
from collections import Counter
read = sys.stdin.buffer.read 
readline = sys.stdin.buffer.readline 
readlines = sys.stdin.buffer.readlines 
sys.setrecursionlimit(10**7) 

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

counter = Counter(s_lis) 
 
answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Solution (Python):
n=int(input())
s=list(input() for _ in range(n))
d={}

res=0
for c in s:
    c=sorted(c)
    c=''.join(c)
    if c not in d:
        d[c]=1
    else:
        d[c]+=1
for i in d.values():
    res+=(i*(i-1))/2
print(int(res))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    
    
    l=[''.join(sorted(list(input()))) for i in range(n)]

    from collections import Counter
    c=Counter(l)
    
    
    ans=0
    for j in c.values():
        ans+=(j*(j-1))//2
    print(ans)
resolve()

Solution (Python):
from collections import Counter

n = int(input())

s = []
for _ in [0]*n:
  s.append("".join(sorted(list(input()))))

c = Counter(s)

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

Solution (Python):
from collections import Counter

n = int(input())

s = []
for _ in [0]*n:
  s.append("".join(sorted(list(input()))))

c = Counter(s)

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

Solution (Python):

from collections import Counter

N = int(input())
S = [''.join(map(str,(sorted(str(input()))))) for i in range(N)]
counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    s=[sorted(list(input())) for i in range(n)]
    s.sort()
    ans=0
    cnt=1
    for i in range(n-1):
        if s[i]==s[i+1]:
                cnt+=1
                if i ==n-2:
                    ans+=cnt*(cnt-1)//2
        else:
            if cnt>=2:
                ans += cnt * (cnt - 1) // 2
                cnt=1
    print(ans)
resolve()

Solution (Python):
from math import factorial
n = int(input())

dic={}
for i in range(n):
    s=''.join(sorted(list(input())))
    dic[s]=dic.get(s,0)+1

ans=0
for key,value in dic.items():
    if value<2:
        continue
    ans+=factorial(value)//(factorial(2)*factorial(value - 2))
print(ans)