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):
from collections import Counter

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

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

Solution (Python):
import collections
import math

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

ans = 0

for _ in range(N):
    s = input()
    s = "".join(sorted(s))
    if s in word_dict:
        ans += word_dict[s]
        word_dict[s] += 1
    else:
        word_dict[s] = 1
    
print(ans)

Solution (Python):
import collections as c

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

D = c.Counter(S)

D_value = []

for a in D.values():
	D_value.append(a)

ans = 0

for i in D_value:
	if i == 0:
		continue
	ans += (i * (i-1)) // 2

print(ans)

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

ans=0
lis={}
for word in s:
  arr=[]
  for let in word:
    arr.append(let)
  arr.sort()
  new=''
  for let in arr:
     new += let
  if new in lis:
    lis[new] += 1
    ans += lis[new]
  else: 
    lis[new] = 0
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
ss = [input() for _ in range(n)]

sorted_ss = [''.join(sorted(s)) for s in ss]
sorted_counter = Counter(sorted_ss)

cnt = sum([n * (n - 1) // 2 for n in sorted_counter.values()])
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter
def print_ans(N, sr):
    """Test Case
    >>> print_ans(3, ["acornistnt", "peanutbomb", "constraint"])
    1
    >>> print_ans(2, ["oneplustwo", "ninemodsix"])
    0
    >>> print_ans(5,["abaaaaaaaa","oneplustwo","aaaaaaaaba","twoplusone","aaaabaaaaa"]) 
    4
    """
    for i in range(N):
        sr[i] = "".join(sorted(sr[i]))
    C = Counter(sr)
    ans = 0
    for v in C.values():
        ans += v * (v - 1) // 2
    print(ans)

    
    
    
    
    
    


if __name__ == '__main__':
    N = int(input().rstrip())
    sr = [ input().rstrip() for _ in range(N)]
    print_ans(N, sr)

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


al_list = [chr(ord('a') + i) for i in range(26)]

num_list = []
count_by_kw = Counter()
for _s in s_list:
    num = ''
    for _al in al_list:
        num += str(_s.count(_al))
    
    num_list.append(num)

count_list = list(Counter(num_list).values()) 

ans = 0
for i in range(len(count_list)):
    k = count_list[i]
    ans += k * (k - 1) / 2

print(int(ans))

Solution (Python):
import sys
import collections


def alg_combination(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i)
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i)
        return denominator // molecule


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    for i in range(n):
        d["".join(sorted(list(str(readline().rstrip().decode('utf-8')))))] += 1
    t = 0
    for k, v in d.items():
        if v >= 2:
            t += alg_combination(v, 2)
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))

dic = {}
ans = 0

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

Solution (Python):
import collections

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

s_list_cnt = collections.Counter(s_list)
total = 0
for cnt in s_list_cnt.values():
  total += cnt * (cnt - 1) / 2
  
print(int(total))

Solution (Python):
N = int(input())
S = {}
ans = 0
for i in range(N):
    a = input()
    s = [ ]
    for j in range(10):
        s.append(a[j])
    s.sort()
    b =s[0]
    for k in range(1,10):
        b += s[k]
    if b in S:
        ans += S[b]
    else:
        S[b] = 0
    S[b] += 1
print(ans)

Solution (Python):
n = int(input())
s = []
ans = 0

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

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

Solution (Python):
N=int(input())
d=dict()
ans=0
for i in range(N):
    s="".join(sorted(input()))
    if s not in d.keys():
        d[s]=0
    ans+=d[s]
    d[s]+=1
print(ans)

Solution (Python):
alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
ans = 0
for _ in range(n):
    s = str(input())
    s = "".join(sorted(s))
    if s not in res.keys():
      res[s] = 1
    else:
      ans += res[s]
      res[s] += 1
print(ans)

Solution (Python):
alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
for _ in range(n):
    s = str(input())
    freqency = [0 for _ in alphabet]
    for __ in s:
        freqency[alphabet.index(__)] += 1
    freq = "".join([str(___) for ___ in freqency])
    if freq not in res:
        res[freq] = 1
    else:
        res[freq] += 1

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

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

for s in S:
  ls = str(sorted(list(s)))
  if ls in count:
    count[ls] +=1
  else:
    count[ls] = 1

for s in count:
  count[s] = count[s]*(count[s]-1)//2 
print(sum(count.values()))

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

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

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

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

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

Solution (Python):
from operator import itemgetter

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


s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

for i in range(1, n):
    if l == s_sort[i]:
        
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

print(count)

Solution (Python):
N = int(input())
s = {}
ans = 0
for i in range(N):
    a = "".join(sorted(input()))
    if a not in s:
        s.setdefault(a,0)
    else:
        s[a] += 1
        ans += s[a]
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)
def moji(s):
    tmp = []
    for i in range(10):
        tmp.append(s[i])
    tmp.sort()
    new_s = ''
    for i in range(10):
        new_s += tmp[i]
    return new_s

N = int(input())
dic = {}
ans = 0
for i in range(N):
    tmp = moji(input())
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic.values():
    if i == 1:
        continue
    ans += C(i,2)
print(ans)

Solution (Python):
N=int(input())
s=[0]*N
for i in range(N):
    s[i] = input()
    s[i] = sorted(s[i])
s=sorted(s)
counter=1
sum=0
for i in range(N-1):
    if s[i] == s[i+1]:
        counter+=1
    else:
        sum+=counter*(counter-1)//2
        counter=1
sum+=counter*(counter-1)//2
print(sum)

Solution (Python):

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


dic = {}
for i in li:
    if (i in dic):
        dic[i] += 1
    else:
        dic[i] = 1

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

ans = 0

for i in dic.values():
    ans += calc(i)


print(ans)

Solution (Python):
n = int(input())
b = []
for i in range(n) :
  b.append(sorted(list(input())))
b.sort()
prev = [1,2,3,4]
tot = 1
ans = 0
for i in range(n) :
  if b[i]==prev :
    tot+=1
  else :
    ans+=(tot*(tot-1)/2)
    tot=1
    prev = b[i]
if tot>1 :
  ans+=(tot*(tot-1)/2)
print(int(ans))

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

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

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

Solution (Python):
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
print(sum([int(v*(v-1)/2) for v in d.values()]))

Solution (Python):
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
ans = 0
val = d.values()
for v in val:
    ans += v*(v-1)/2
print(int(ans))

Solution (Python):
import collections
N = int( input() )
char_list = []
ans = 0 
for i in range(N):
    c = sorted( input() ) 
    c_new = "".join(c)
    char_list.append(c_new)
    
t = collections.Counter(char_list)

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

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

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

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

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

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

Solution (Python):
import collections

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

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

Solution (Python):
import collections

N = int(input())
S = collections.defaultdict(int)
for _ in range(N):
  s = ''.join(sorted(input().rstrip()))
  S[s] += 1

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

Solution (Python):
import sys
input = sys.stdin.readline

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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

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

Solution (Python):



import collections
n = int(input())

sl = []
for _ in range(n):
    s = sorted(list(input()))
    sl.append(s)

before_s = ""
ans = 0
point = 1
for i in sorted(sl):
    if i == before_s:
        point += 1
    else:
        before_s = i
        ans += int(point * (point - 1) / 2)
        point = 1
ans += int(point * (point - 1) / 2)
print(ans)

Solution (Python):
N = int(input())
S = sorted([sorted(input()) for _ in range(N)])
k = 0
ans = 0
for i in range(1, N):
    if S[i] == S[i-1]:
        k += 1
        ans += k
    else:
        k = 0
print(ans)

Solution (Python):

n = int(input())
sl = []
ans = 0
for i in range(n):
    s = "".join(sorted(input()))
    sl.append(s)
sl.sort()
bi = ""
tmp = 0
for i in sl:
    if (bi == i):
        tmp += 1
    else:
        ans += (tmp+1)*(tmp)//2
        tmp = 0
    bi = i
ans += (tmp+1)*(tmp)//2

print(ans)

Solution (Python):
n=int(input())
dic={}
for _ in range(0,n):
  s="".join(sorted(input()))
  if s in dic:
    dic[s]+=1
  else:
    dic[s]=1
    
ans=0    
for a in dic.values():
  ans+=(a*(a-1))/2
  
print(int(ans))

Solution (Python):
n = int(input())
s = []
for _ in range(n):
    tmp = list(input())
    tmp.sort()
    s.append(str(tmp))
cnt = 0
dict = {}
for x in s:
    if x in dict:
        cnt += dict[x]
        dict[x] += 1
    else:
        dict[x] = 1
print(cnt)

Solution (Python):
n = int(input())
dic = {}
ans = 0
for i in range(n):
  s = "".join(sorted(input()))
  a = dic.get(s)
  if a is None:
    dic[s] = 1
  else:
    ans += a
    dic[s] += 1
print(ans)

Solution (Python):
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

Solution (Python):
n = int(input())
strings_list = [list(input()) for i in range(n)]
counter = 0
dict = {}
 
for strings in strings_list:
    strings = "".join(sorted(strings))
    if strings in dict.keys():
        counter += dict[strings]
        dict[strings] += 1
    else:
        dict[strings] = 1
print(counter)

Solution (Python):
N = int(input())
s_dict = {}
ans = 0
for i in range(N):
  string = list(input())
  string.sort(reverse=False)
  if tuple(string) in s_dict:
    s_dict[tuple(string)] += 1
  else:
    s_dict[tuple(string)] = 1

for i in s_dict.values():
  if i != 1:
    ans += sum([i for i in range(1,i)])

print(ans)

Solution (Python):

N = int(input())
s_dict = {}
ans = 0


for i in range(N): 
  
  string = list(input())
  string.sort(reverse=False)
  
  
    
  if tuple(string) in s_dict:
    s_dict[tuple(string)] += 1
  else:
    s_dict[tuple(string)] = 1

for i in s_dict.values():
  if i != 1:
    ans += sum([i for i in range(1,i)])

print(ans)

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

num=1
for i in range(N-1):
    if(s[i]==s[i+1]):
        num += 1
    elif(num>1):
        count += num*(num-1)/2
        num = 1
    
if(num>1):
    count += num*(num-1)/2
print(int(count))

Solution (Python):
def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())
 
    for s in array_s:
        array.append(''.join(sorted(s)))
    array = sorted(array)
    ans = 0
    count = 1
    for i in range(n-1):
        if array[i] == array[i+1]:
            count += 1
            if i != n-2:
                continue
        ans += int(count*(count-1)/2)
        count = 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
dic = {}
plis = [2]
for i in range(3,150):
    s =True
    for p in plis:
        if i%p==0:
            s = False
    if s:
        plis.append(i)
for i in range(N):
    foo = 1
    for j in input():
        j = ord(j) - ord("a")
        foo *= plis[j]
    try:
        dic[foo] += 1
    except:
        dic[foo] = 1
ans = 0
for n in dic.values():
    ans += n*(n-1)//2
print(ans)

Solution (Python):
n=int(input())
d=[list(input()) for i in range(n)]
count=0
ans=0
for i in range(n):
  d[i].sort()
d.sort()

for i in range(n-1):
  if d[i]==d[i+1]:
    count+=1
  elif d[i]!=d[i+1]:
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  if i==(n-2):
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  
print(int(ans))

Solution (Python):
N=int(input())
q=[]  
for i in range(N):
    q+=[list(input())]
    q[i].sort()
q.sort() 
i=0
s=0
z=0 
while i<N-1:
    if q[i]!=q[i+1]:
        z+=((s*(s+1))//2)
        s=0
    else:
        s+=1
    i+=1
z+=((s*(s+1))//2)
print(z)

Solution (Python):
N=int(input())
n=0
a=0
L=sorted([sorted(list(input())) for _ in range(N)])
L.append("p")
for i in range(N):
  if L[i]!=L[i+1]:
    n+=(i-a)*(i-a+1)/2
    a=i+1
print(int(n))

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

print(ans)

Solution (Python):
n = int(input())
strings_list = [list(input()) for i in range(n)]
counter = 0
dict = {}

for strings in strings_list:
    strings = "".join(sorted(strings))
    if strings in dict.keys():
        counter += dict[strings]
        dict[strings] += 1
    else:
        dict[strings] = 1
print(counter)

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

for l in L:
    m = ''.join(sorted(l))
    M.append(m)

import collections
c = collections.Counter(M)
d = list(c.values())
e = []
for i in range(len(d)):
    e.append(sum(range(1,d[i])))

print(sum(e))

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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n=int(input())
L = []
for i in range(n):
  a = input()
  a = sorted(a)
  L.append(a)
L = sorted(L)


k=1
sum=0
for i in range(n-1):
  if L[i]==L[i+1]:
    k += 1
  else:
    if k!=1:
      sum += cmb(k,2)
    k=1
if k!=1:
  sum += cmb(k,2)
print(sum)

Solution (Python):
from collections import defaultdict
import sys
def input() -> str:
    return sys.stdin.readline()
n = int(input())
s = [input() for _ in range(n)]
cnt = defaultdict(int)
ans = 0
for si in s:
    ana = "".join(sorted(si))
    ans += cnt[ana]
    cnt[ana] += 1
print(ans)

Solution (Python):
from collections import defaultdict
import sys
def input() -> str:
    return sys.stdin.readline()
n = int(input())
s = [input() for _ in range(n)]
cnt = defaultdict(int)
for si in s:
    cnt["".join(sorted(si))] += 1
ans = 0
for v in cnt.values():
    ans += sum(range(1, v))
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
s = [input() for _ in range(n)]
cnt = defaultdict(int)
for si in s:
    cnt["".join(sorted(si))] += 1
ans = 0
for v in cnt.values():
    ans += sum(range(1, v))
print(ans)

Solution (Python):
import collections
N = int(input())
S = []
for _ in range(N):
  s = list(input())
  s.sort()
  s = ''.join(s)
  S.append(s)
c = collections.Counter(S)
v = list(c.values())
count = 0
for j in v:
  count += j*(j-3)/2+j
print(int(count))

Solution (Python):
import collections as cl

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

cs = cl.Counter(s)
num = list(cs.values())
count = 0

for j in range(0, len(num)):
    if num[j] != 1:
        count = count + (num[j] * (num[j] - 1)) / 2

print(int(count))

Solution (Python):
import unittest
from io import StringIO
import sys
from math import factorial
from scipy.misc import comb
import math


def resolve():
    N = int(input())
    d = {}
    count = 0
    for i in range(N):
        s = list(input())
        s.sort()
        s = ''.join(s)
        if s not in d.keys():
            d[s] = 1
        else:
            count += d[s]
            d[s] += 1

    print(count)


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):
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

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

dic = {}
ans = 0

for i in range(n):
    s = input()
    sss = "".join(sorted(s))
    
    
    if sss in dic:
        val = dic[sss]
        dic[sss] = val + 1
        ans = ans + val
        
    else:
        dic.setdefault(sss, 1)


print(ans)

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

memo = {}
ans = 0

for i in range(n):
    si = ('').join(S[i])
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1

print(ans)

Solution (Python):

def inp():
  return list(input())

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

for i in range(N):
  s = str(sorted(inp()))
  
  if s in res:
    res[s] += 1
  else:
    res[s] = 1
    

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

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

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


memo={}
ans=0
for i in range(n):
  if S[i] not in memo:
    memo[S[i]]=1
  else:
    memo[S[i]]+=1
    ans+=memo[S[i]]-1
print(ans)

Solution (Python):
N=int(input())
q=[]  
for i in range(N):
    q+=[list(input())]
    q[i].sort()
q.sort() 
i=0
s=0
z=0 
while i<N-1:
    if q[i]!=q[i+1]:
        z+=((s*(s+1))//2)
        s=0
    else:
        s+=1
    i+=1
z+=((s*(s+1))//2)
print(z)

Solution (Python):
def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(''.join(sorted(s)))
    array = sorted(array)
    ans = 0
    count = 1
    for i in range(n-1):
        if array[i] == array[i+1]:
            count += 1
            if i != n-2:
                continue
        ans += int(count*(count-1)/2)
        count = 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

N = int(input())

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

d = collections.Counter(s)

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

print(cnt)

Solution (Python):
n = int(input())
b = list()
for _ in range(n):
    
    s = input()
    a = list()
    for i in range(len(s)):
        a.append(s[i])
    a.sort()
    s = ""
    s = s.join(a)
    
    b.append(s)
    
b.sort()
b.append("zzzzzzzzzzzzzzz")

ans = 0
cn  = 1
for i in range(0,len(b)-1):
    if(b[i]==b[i+1]):
        cn += 1
    else:
        ans += (cn*(cn-1))//2
        cn  = 1

print(ans)

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

letter_dict = {}
count = 0

for s in s_list:
    sort_list = [l for l in s]
    sort_list.sort()
    sort_str = ''.join(sort_list)
    if hash(sort_str) in letter_dict:
        letter_dict[hash(sort_str)] += 1
    else:
        letter_dict[hash(sort_str)] = 1

for k,v in letter_dict.items():
    count += v*(v-1)//2

print(count)

Solution (Python):

import sys
import collections
from itertools import groupby

def solve(N: int, s: "List[str]"):
    s = [sorted(s[i]) for i in range(N)]
    s.sort()
    group = groupby(s)
    answer = 0
    for _, group in group:
        a = len(list(group))
        answer += int(a*(a-1)/2) if a > 1 else 0
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    s = [next(tokens) for _ in range(N)]  
    solve(N, s)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import collections
from itertools import groupby

def solve(N: int, s: "List[str]"):
    s = [sorted(s[i]) for i in range(N)]
    s.sort()
    group = groupby(s)
    answer = 0
    for key, group in group:
        a = len(list(group))
        answer += int(a*(a-1)/2) if a > 1 else 0
    print(answer)
   


    
    
    
    
    
    
    
        
    
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    s = [next(tokens) for _ in range(N)]  
    solve(N, s)

if __name__ == '__main__':
    main()

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

s = list([input() for _ in range(N)])

for i in range(N):
    s_temp=list(s[i])
    s_temp.sort()
    s[i] = str(''.join(s_temp))
    
s_ctr = collections.Counter(s)

cnt=0
for j in s_ctr.values():
    if j>1:
        cnt += math.factorial(j)//(math.factorial(2)*math.factorial(j-2))
    
print(cnt)

Solution (Python):
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

Solution (Python):
N = int(input())
dic = {}
for i 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():
    ans += v * (v - 1) // 2

print(ans)

Solution (Python):
n=int(input())
a=[]
c=[]
count=0
ans=0
for i in range(n):
    x=list(input())
    a.append(x)
for j in range(n):
    a[j].sort()
a.sort()
for k in range(n-1):
    if a[k]==a[k+1]:
        if k==0 or a[k-1]!=a[k]:
            count+=2
        else:
            count+=1
        if k==n-2:
            c.append(count)
    else:
        c.append(count)
        count=0
for l in range(len(c)):
    ans+=int(c[l]*(c[l]-1)/2)
print(ans)

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

Solution (Python):
import sys
from itertools import accumulate
input = sys.stdin.readline

def acm(x):
    ary = [ i for i in range(x) ]
    return sum(ary)

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

res = 0
for obj in strings:
    res += acm(strings[obj])
print(res)

Solution (Python):
N = int(input())
li = []
for i in range(N):
  a = list(input())
  a.sort()
  li.append("".join(a))
  
dic = {}
li2 = []
for i in range(len(li)):
  if not li[i] in dic:
    dic[li[i]] = 1
    li2.append(li[i])
  else:
    dic[li[i]] += 1

b = 0
for i in range(len(li2)):
  c = dic[li2[i]]
  if c == 1:
    b += 0
  else:
    b += c*(c-1)/2
print(int(b))

Solution (Python):

from collections import Counter


def main():
    _, *S = open(0).read().split()
    cnt = Counter("".join(sorted(s)) for s in S).values()
    ans = sum(i * (i - 1) // 2 for i in cnt)
    print(ans)


if __name__ == "__main__":
    main()

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

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

list.sort(S) 

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

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

print(ans)

Solution (Python):
def main():
	N = int(input())
	s = {}
	pair = 0
	for _ in range(N):
		b = "".join(sorted([a for a in input()]))
		if b in s.keys():
			pair += s[b]
			s[b] += 1
		else:
			s[b] = 1
	print(pair)
main()

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

s_dic={}
for i in range(N):
  s=list(input())
  s.sort()
  s_str="".join(s)
  
  if s_str in s_dic:
    s_dic[s_str]+=1
  else:
    s_dic[s_str]=1


answer=0
for key in s_dic:
  answer+=(s_dic[key]*(s_dic[key]-1))//2

print(answer)

Solution (Python):
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)
n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)

Solution (Python):
def t(s):
    a = [''.join(sorted(i)) for i in s]
    b = {}
    r = 0
    for i in a:
        if i in b.keys():
            r += b[i]
            b[i] += 1
        else:
            b[i] = 1
    return int(r)


if __name__ == '__main__':
    n = int(input())
    print(t([input() for i in range(n)]))

Solution (Python):
from collections import defaultdict as dd
from math import factorial as f
dic = dd(int)
N = int(input())
for _ in range(N):
	dic["".join(sorted(input()))] += 1
print(sum(map(lambda x: f(x)//f(x-2)//2 if x > 1 else 0, dic.values())))

Solution (Python):
n = int(input())
d_ans = {}
for _ in range(n):
  line = input()
  char_lst = 26*[0]
  for char in line:
    char_lst[ord(char) - 97] += 1
  try:
    char_tup = tuple(char_lst)
    d_ans[char_tup] += 1
  except KeyError:
    d_ans[char_tup] = 1

ans = 0    
for val in d_ans.values():
  ans += (val*(val-1)) >> 1
print(ans)

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

s.sort()

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

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

Solution (Python):
from collections import defaultdict
n=int(input())
l=defaultdict(int)
for i in range(n):
  l1=sorted(list(input()))
  w1="".join(l1)
  l[w1]+=1
count=0
for i in l:
  if l[i]!=1:
    count+=l[i]*(l[i]-1)//2
print(count)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
dict = {}
for _ in range(N):
    str = input()
    st = ''.join(sorted(str))
    if st not in dict:
        dict[st] = 1
    else:
        dict[st] += 1
answer = 0
for key in dict:
    l = dict[key]
    answer += l*(l-1)//2

print(answer)

Solution (Python):
from collections import defaultdict

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

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

Solution (Python):
import collections

n = int(input())
S = []
count = 0
for _ in range(n):
    S.append(''.join(sorted(list(input()))))

for i, v in collections.Counter(S).items():
    for i in range(1, v):
        count += i

print(count)