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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    lst = []
    for _ in range(n):
        st = S()
        st = list(st)
        st.sort()
        lst.append("".join(st))

    ans = 0
    dic = collections.Counter(lst)
    for key,value in dic.items():
        if value >= 2:
            ans += value*(value-1)//2
    print(ans)
main()

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

Solution (Python):
from collections import Counter

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

sort_s = []
for s in S:
    sort_s.append(''.join(sorted(s)))

count = dict(Counter(sort_s))

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

print(int(ans))

Solution (Python):
from collections import Counter

n = int(input())
w = [""] * n
for i in range(n):
    w[i] = list(input())
    w[i].sort()
    w[i] = "".join(w[i])

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

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

Solution (Python):
N = int(input())
ls = {}
ans = 0

for i in range(N):
  s = input()
  ns = ''.join(sorted(s))
  if ns in ls:
    ans += ls[ns]
    ls[ns] += 1
  else:
    ls[ns] = 1
    
print(ans)

Solution (Python):
n = int(input())
mydict = {}
for _ in range(n):
    tmp=sorted(input(), key=str.lower)
    tmp = ''.join(sorted(tmp))
    if tmp in mydict:
        mydict[tmp]+=1
    else:
        mydict.setdefault(tmp, 1)
ans = 0
for i in mydict.values():
    ans+=i*(i-1)/2
print(int(ans))

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

print(ans)

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    l = []
    for s in S:
        tmp_l = []
        for c in s:
            tmp_l.append(ord(c))
        tmp_l = sorted(tmp_l)

        tmp_s = ""
        for n in tmp_l:
            tmp_s += chr(n)
        l.append(tmp_s)

    C = Counter(l)
    ans = 0
    for c in C.values():
        if c > 1:
            ans += factorial(c) // (factorial(c - 2) * factorial(2))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for _ in range(N)]

new_S = []
for s in S:
    tmp = [_ for _ in s]
    tmp = ''.join(sorted(tmp))
    new_S.append(tmp)

c = Counter(new_S)

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

ans = 0
for n in c.values():
    ans += combinations_count(n, 2)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

L = []
for s in S:
    c = "".join(sorted(s))
    L.append(c)
L.sort()
S = set(L)

C = Counter(L)

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

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

Solution (Python):
import collections
n = int(input())
a = []
for i in range(n):
  s = input()
  b = list(s)
  b.sort()
  b = ''.join(b)
  a.append(b)
c = collections.Counter(a)
ans = 0
for e in c:
  ans += c[e] * (c[e] - 1) // 2
print(ans)

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

ans = 0
word = {}
for i in range(N):
    S_word = sorted(input())
    key = "".join(S_word) 
    if key in word:
       word[key] += 1
       ans += word[key]
    else:
        word[key] = 0

print(ans)

Solution (Python):
from collections import Counter

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N = int(input())
S = []
for _ in range(N):
    string = sorted(input())
    string = "".join(string)
    S.append(string)

S_counter = Counter(S)

ans = 0
for i in S_counter.values():
    if i != 1:
        number = cmb(i, 2)
        ans = ans + number

print(ans)

Solution (Python):
from collections import Counter

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N = int(input())
S = []
for _ in range(N):
    string = sorted(input())
    string = "".join(string)
    S.append(string)

S_counter = Counter(S)

ans = 0
for i in S_counter.values():
    if i != 1:
        number = cmb(i, 2)
        ans = ans + number

print(ans)

Solution (Python):









import os
import sys




def main():
    n = int(input())
    ans_box = dict()
    for _ in range(n):
        s = sorted(map(str, input()))
        if ''.join(s) in ans_box.keys():
            ans_box[''.join(s)] += 1
        else:
            ans_box[''.join(s)] = 1
    ans = 0
    for key, value in ans_box.items():
        if value == 1:
            pass
        else:
            ans += value*(value-1)//2
    print(ans)

if __name__ == "__main__":
    main()

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

ans = 0
for s in strings:
    x = strings[s]
    ans += x * (x-1) // 2

print(ans)

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

d = {}
for _ in range(n):
    string = "".join(sorted(list(input())))
    if string not in d:
        d[string] = 1
    else:
        d[string] += 1

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

print(ans)

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

dic = {}
for _ in range(N):
    s = ''.join(sorted(input()))

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

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

Solution (Python):
import collections

n=int(input())
lst=[]
ans=0

for i in range(n):
    s=input()
    lst.append(''.join(sorted(s)))

c=collections.Counter(lst)

for i in set(lst):
    x=c[i]

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


print(ans)

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 = []
for i in range(N):
    s = [c for c in input()]
    s.sort()
    S.append("".join(s))

counter = Counter(S)

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


print(res)

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

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

S_lst = {}
for i in range(N):
  if S[i] in S_lst:
    S_lst[S[i]] += 1
  else:
    S_lst[S[i]] = 1


sum_ = 0
for key in S_lst:
    sum_ += int((S_lst[key] * (S_lst[key] - 1)) / 2)

print(sum_)

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())

s = [0] * N

patterns = defaultdict(int)

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

    list_string = list(s[i])
    list_string.sort()

    list_string = "".join(list_string)
    patterns[list_string] += 1

ans = 0
for p in patterns.values():
    if p >= 2:
        ans += comb(p, 2)

print(ans)

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
dict_a = {}

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

print(cnt)

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

Solution (Python):
N = int(input())
S = []
for _ in range(N):
    S.append(input())
for i in range(N):
    S[i] = sorted(S[i])
S = sorted(S)
ans = 0
sa = 1
for i in range(N):
    if i == N-1:
        if sa == 1:
            break
        else:
            ans += int(sa * (sa - 1) / 2)
            break
    if S[i] == S[i+1]:
        sa += 1
    else:
        if sa == 1:
            continue
        else:
            ans += int(sa * (sa - 1) / 2)
            sa = 1
print(ans)

Solution (Python):
n = int(input())
count =0
store_list=[]
dictA={}
ans_list=[1]*n
for _ in range(n):
    s = input()
    s_list = list(s)
    s_list.sort()
    a =tuple(s_list)
    dictA.setdefault(a,0)
    dictA[a] +=1 
    

total = 0
for value in dictA.values() :
    total += value*(value-1)/2
       
print(int(total))

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

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

Solution (Python):
N=int(input())
List = []
ListMid = []
dictA = {}
res =0
for i in range(N):
  S = input()
  ListMid = list(S)
  ListMid.sort()
  a = tuple(ListMid)
  dictA.setdefault(a,0) 
  dictA[a] += 1
for value in dictA.values():
  if value == 1:
    pass
  else:
    res += value*(value-1)//2
print(res)

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

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

Solution (Python):
N = int(input())
s = []
for i in range(N):
  tmp = list(input())
  tmp.sort()
  s.append("".join(tmp))

s.sort()
m = {}
for i in range(len(s)):
  if s[i] in m.keys():
    m[s[i]] += 1
  else:
    m[s[i]] = 1

v = [int(x * (x-1) / 2) for x in list(m.values())]
print(sum(v))

Solution (Python):
from collections import Counter










n = int(input())

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

c = Counter(clist)

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

Solution (Python):
import collections

N = int(input())
S = [tuple(sorted(input())) for _ in range(N)]
c = collections.Counter(S)
ans = 0
for i in set(S):
    n = c[i]
    ans += 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 i in set(S):
    n = c[i]
    ans += n*(n-1)//2
print(ans)

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

Solution (Python):
n = int(input())
A = []
for i in range(n):
    i = list(map(str,input()))
    i.sort()
    A.append(i)

A.sort()
tmp = A[0]
cnt = 0
ans = 0
for i in range(1,n):
    if tmp == A[i]:
        cnt += 1
    else:
        tmp = A[i]
        for j in range(cnt):
            ans += cnt
            cnt -= 1
if cnt >= 1:
    for j in range(cnt):
        ans += cnt
        cnt -= 1

print(ans)

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

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

dic = {};
count = 0;
for i in range(N):
  chars = list(input());
  chars.sort();
  sorted_str = "".join(chars);
  
  
  if sorted_str in dic:
    dic[sorted_str] += 1;
    count += dic[sorted_str];
  else:
    dic[sorted_str] = 0;
  
print(count);

Solution (Python):
N = int(input())
S = []
for _ in range(N):
	t = ''.join(sorted(input()))
	S.append(t)
SS = sorted(S)
ans = 0
t = 0
import math
for i in range(1, N):
	if SS[i - 1] == SS[i]:
		t += 1
		ans += t
	else:
		t = 0
print(ans)

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic["".join(sorted(i))]
        dic["".join(sorted(i))] +=1
    else:
        dic["".join(sorted(i))] = 1
print(ans)

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

strings = {}

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

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

Solution (Python):
import sys

input = sys.stdin.readline
D = {}
for _ in range(int(input())):
    d = {}
    for s in sorted(input().rstrip()):
        if s in d:
            d[s] += 1
        else:
            d[s] = 1
    ds = "".join((k + str(v)) for k, v in d.items())
    if ds in D:
        D[ds] += 1
    else:
        D[ds] = 1

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

Solution (Python):
def get( s ):
    sum=0
    s = sorted(s) 
    for i in range(len(s)):
        sum += int(ord(s[i])*(1<<(i*5)))
    return sum

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

H=[0]*n
for i in range(n):
    H[i]=get(S[i])

H.sort()
c=0
ans=0
for i in range(n-1):
    if H[i]==H[i+1]:
        c+=1
    else:
        ans += c*(c+1)//2
        c=0
ans += c*(c+1)//2
print(ans)

Solution (Python):
N = int(input())
d = {}
ans = 0
for i in range(N):
    t = str(sorted(input()))
    if (d.get(t, "Not") == "Not"):
        d[t] = 1
    else:
        ans += d[t]
        d[t] += 1
print(ans)

Solution (Python):
S=[]
n = int(input())
for i in range(n):
    s=''.join(sorted(input()))
    S.append(s)
import collections
from scipy.special import comb
a=0
Sd=list(set(S))
c = collections.Counter(S)
for p in  range(len(Sd)):
    if c[Sd[p]] >=2:
        a  += comb(c[Sd[p]], 2, exact=True)
print(a)

Solution (Python):
import collections

n = int(input())
s = list(sorted(input()) for _ in range(n))

l = []
for li in s:
    st = ''
    for x in li:
        st += x
    l.append(st)

c = collections.Counter(l)

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

print(ans)

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

t = []

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)

t.sort()

s = 0
c = 0
l = []

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

if c > 0:
    s += c * (c+1) // 2

print(s)

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

ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""


t=ii()
d=defaultdict(int)
for _ in range(t):
    k=ip()
    k.sort()
    k="".join(k)
    d[k]+=1
ans=0    
for i in d.keys():
    ans+=(d[i]*(d[i]-1))//2
print(ans)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    s = [sorted(list(input().rstrip())) for _ in range(n)]
    s.sort()

    ans = 0
    trial = s[0]
    tri_num = 0
    for i in s[1:]:
        if trial == i:
            tri_num += 1
        else:
            ans += tri_num*(tri_num+1)//2
            tri_num = 0
            trial = i
    if tri_num != 0:
        ans += tri_num*(tri_num+1)//2
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):
n=int(input())
s=[]
for i in range(n):
    x=list(input())
    x=sorted(x)
    s.append("".join(x))
s=sorted(s)
m=1
ans=0
for i in range(n-1):
    if s[i]==s[i+1]:
        m+=1
    else:
        ans+=m*(m-1)//2
        m=1
ans+=m*(m-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=["".join(sorted(input())) for _ in range(N)]
d={}
count=0
for s in S:
  if s in d:
    count+=d[s]
    d[s]+=1
  else:
    d[s]=1
print(count)

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

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

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

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
    s = list(input())
    s.sort()
    js = ''.join(s)
    if js in d:
        d[js] += 1
    else:
        d[js] = 1

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

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

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

table = {}

ans = 0
for s in S:
    if s in table:
        table[s] += 1
    else:
        table[s] = 1

for k in table:
    ans += table[k] * (table[k] - 1)

ans //= 2
print(ans)

Solution (Python):
n = int(input())
a = []
ans = 0
for i in range(n):
    a.append(sorted(input()))
a.sort()
flg = 0
for i in range(1,n):
    if a[flg] != a[i]:
        z = i - 1 - flg
        ans += (1 + z) * z // 2
        flg = i
z = n - 1 - flg
ans += (1 + z) * z // 2
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
S = [[0]*26 for _ in range(N)]
for i in range(N):
    for s in input():
        S[i][ord(s)-ord("a")] += 1
    S[i] = tuple(S[i])
res = 0
for value in Counter(S).values():
    res += value*(value-1)//2

print(res)

Solution (Python):

import collections
import math


def main():
    N = int(input())
    S = ["".join(sorted(input())) for i in range(N)]
    cnt = collections.Counter(S)
    ans = 0
    for v in cnt.values():
        if v != 1:
            ans += math.factorial(v) // (math.factorial(v - 2) * 2)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = I()
s = [sorted(list(_S())) for _ in range(N)]
ss = [0] * N
for i in range(N):
    ss[i]=''.join(s[i])

c = collections.Counter(ss)


def nCr(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

key, counts = zip(*c.most_common())
ans = 0
for  count in counts:
    if count > 1:
        ans += nCr(count,2)
print(ans)

Solution (Python):
n=int(input())
arr=[]
from collections import Counter
c=Counter([])
for _ in range (n):
    s=input()
    z=[item for item in s]
    z.sort()
    z=tuple(z)
    c[z]+=1
ans=0
for item in c.values():
    ans+=(item*(item-1))//2
print (ans)

Solution (Python):
n = int(input())
S = ["".join(sorted(input())) for _ in range(n)]
counters = {}

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

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

Solution (Python):
n = int(input())
S = ["".join(sorted(input())) for _ in range(n)]
counters = {}

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

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

Solution (Python):
import sys
input()
ans,d=0,{}
for ln in sys.stdin:
    s=''.join(sorted(ln))
    ans+=d.setdefault(s,0)
    d[s]+=1
print(ans)

Solution (Python):
import sys
input()
ans,d=0,{}
for ln in sys.stdin:
    s=''.join(sorted(ln))
    ans+=d.setdefault(s,0)
    d[s]+=1
print(ans)

Solution (Python):
import sys
input()
ans,c=0,{}
for ln in sys.stdin:
    s=''.join(sorted(ln))
    ans+=c.setdefault(s,0)
    c[s]+=1
print(ans)

Solution (Python):
import sys
N=int(input())
ans,c=0,{}
for _ in range(N):
    s=''.join(sorted(next(sys.stdin)))
    if s not in c:
         c[s]=0
    ans+=c[s]
    c[s]+=1
print(ans)

Solution (Python):
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()
ans=0
pairs=1
for i in range(n-1):

    if s[i]==s[i+1]:
        pairs += 1
    else:      
        ans += pairs*(pairs-1)/2
        pairs =1
if pairs != 1:
    ans += pairs*(pairs-1)/2
    pairs =1
print(int(ans))

Solution (Python):


N = int(input())
alp = [chr(i) for i in range(97, 97+26)]
L = []
for i in range(N):
    s = list(input())
    L.append(s)
for i in range(N):
    L[i].sort()
L.sort()

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

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

Solution (Python):
n = int(input())
counter = dict()
for i in range(n):
  s = ''.join(sorted(input()))
  if not s in counter:
    counter[s] = 0
  counter[s] += 1
print(sum(x * (x-1) // 2 for x in counter.values()))

Solution (Python):
import sys
N = int(input())
counts = {}
for _ in range(N):
    s = tuple(sorted(sys.stdin.readline()))
    counts[s] = counts.get(s, 0) + 1
ans = 0
for count in counts.values():
    if count > 1:
        ans += (count * (count - 1) // 2)
print(ans)

Solution (Python):
import collections


def main():
    n = int(input())
    print(sum(cVal * (cVal - 1) // 2 for cVal in collections.Counter(
        [''.join(sorted(list(input()))) for _ in range(n)]).values()))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import collections
import bisect


def main():
    n = int(input())
    s = [''.join(sorted(list(input()))) for _ in range(n)]
    c = collections.Counter(s)
    cVals = c.values()
    cSum = 0
    for cVal in cVals:
        cSum += cVal * (cVal - 1) // 2
    print(cSum)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    N = int(input())
    
    
    
    
    ans=0
    tc=Counter()
    for _ in range(N):
        s=input()
        c=Counter(s)
        l=tuple(c[num2alp(i)] for i in range(26))

        tc[l]+=1
    for val in tc.values():
        ans+=val*(val-1)//2
    print(ans)





if __name__ == "__main__":
    main()

Solution (Python):



from collections import Counter




def solve(n,l):
  l_dash = ["".join(sorted(s)) for s in l]
  d = Counter(l_dash)
  return sum(v*(v-1)//2 for v in d.values())


def main():
  N = int(input())
  l = [input() for _ in range(N)]
  print(solve(N,l))
  return

if __name__ == '__main__':
  main()

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

c = Counter(s)
ans = 0

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

print(ans)

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

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


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

ans = 0
for value in dic.values():
    if value >=2:
        ans+=C(value, 2)

print(ans)

Solution (Python):
from collections import Counter

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

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

print(ans)

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

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


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

ans = 0
for value in dic.values():
    if value >=2:
        a= C(value, 2)
        ans+=a

print(ans)

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


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


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

ans = 0
for i in list(S_c.values()):
    if i != 1:
        ans += combinations_count(i, 2)

print(ans)

Solution (Python):
n = int(input())
count_dict = dict()
for _ in range(n):
    s = input()
    s = ''.join(sorted(s))
    count_dict.setdefault(s, 0)
    count_dict[s] += 1

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

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

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

a = collections.Counter(s)

ans = 0

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

print(ans)