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.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Runtime Error

Solution code:
import collections

cnt = 0

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

cnt = dict()
for i in range(N):
    string = collections.Counter(input())
    if string not in string_counters:
        string_counters.append(string)
        cnt[i] = 1
    else :
        cnt[string_counters.index(string)] += 1

output = 0
for k, v in cnt.items():
    output += v - 1
print(output)

Submission status: Runtime Error

Solution code:
n=int(input())
ss=[''.join(sorted(input())) for _ in range(n)]
def p(n):
    if n<=1: return n
    return n+p(n-1)
c=0
for s in set(ss):
    c+=p(ss.count(s)-1)
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
slist = []
for i in range(n):
  s = str(input())
  slist.append(s)
sbinlist = []
alpha2num = lambda s: ord(s) - ord('a') + 1
for j in slist:
  sbin = [0] * 26
  for k in range(10):
    sbin[alpha2num(j[k])] += 1
  sbinlist.append(sbin)
anagram = 0
for l in range(n - 1):
  for m in range(l + 1, n):
    a = [x ^ y for (x, y) in zip(sbinlist[l], sbinlist[m])]
    if sum(a) == 0:
      anagram += 1
print(anagram)

Submission status: Runtime Error

Solution code:
n = int(input())
slist = []
for i in range(n):
  s = str(input())
  slist.append(s)
sbinlist = []
alpha2num = lambda s: ord(s) - ord('a') + 1
for j in slist:
  sbin = [0] * 26
  for k in range(10):
    sbin[alpha2num(j[k])] += 1
  sbinlist.append(sbin)
anagram = 0
for l in range(n - 1):
  for m in range(l + 1, n):
    if sbinlist[l] == sbinlist[m]:
      anagram += 1
print(anagram)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = [sorted(input()) for _ in range(N)]
S = sorted(S)
print(sum(map(lambda x: x*(x-1)//2, Counter(S).values())))

Submission status: Runtime Error

Solution code:
n=int(input())
from collections import defaultdict
d=defaultdict(str)
for _ in range(n):
    s=list(input())
    s.sort()
    n=''.join(s)
    d[n]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
from collections import defaultdict
d=defaultdict(int)
for _ in range(n):
    s=list(input())
    s.sort()
    d[*s]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
from collections import defaultdict
d=defaultdict(int)
for _ in range(n):
    s=list(input())
    s.sort()
    d[s]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        for t in range(T,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
    else:
        continue
print(int(cnt))

Submission status: Runtime Error

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    v=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))

Submission status: Runtime Error

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))

Submission status: Runtime Error

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
print(S.values())
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))

Submission status: Runtime Error

Solution code:
import math
import itertools
from scipy.special import comb
n = int(input())

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

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += comb(num, 2)
print(math.floor(sum))

Submission status: Runtime Error

Solution code:
import math
import itertools
n = int(input())

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

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(math.floor(sum))

Submission status: Runtime Error

Solution code:
n = int(input())

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

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(math.floor(sum))

Submission status: Runtime Error

Solution code:
n = int(input())

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

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(int(sum))

Submission status: Runtime Error

Solution code:
n=int(input())
from collections import Counter 
A=[]
for i in range(n):
  A.append(sorted(list(input())))
  
q=Counter(A);ans=0
for j in q.values():
  ans+= j*(j-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
from collections import Counter as C
A=input()
for i in range(n):
  A.append(sorted(list(input())))
  
q=C(A);ans=0
for j in q.values():
  ans+= j*(j-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
P=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]
n=int(input())
A=[1]*n

for i in range(n):
	s=input()
	for j in range(10):
		A[i] *= P[ord(s[j])]

res=0
for i in range(n):
	for j in range(i+1,n):
		if A[i]==A[j]:
			res += 1
print(res)

Submission status: Runtime Error

Solution code:
import collections
from sympy import prime

N = int(input())
count = 1
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count *= prime(ord(s[j])-ord("a")+1)
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())
ans = sum([(i*(i-1))//2 for i in newlis]) 

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
n = int(input())
s = [list(input()) for _ in range(n)]

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

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] > 2:
        ans += factorial(ss[i]) / 2 / factorial(ss[i]-2)
    else:
        ans += 1
print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
t = []
ans = 0
for i in range(n):
    s[i] = sorted(s[i])

t = set(s)
ans = len(s) - len(t)


print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
cnt=0
l=[(sorted(list(input()))for i in range(n)]

for j in range(n-1):
    for k in range(j+1,n):
        if l[j]==l[k]:
            cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
cnt=0
l=[]
for i in range(n):
            l_i=list(input())
            l_i.sort()
            l.append(l_i)
l.sort()a
#print(l)
for j in range(n-1):
            for k in range(j+1,n):
                        if l[j]==l[k]:
                                    cnt+=1
                                    #print('l[j]',l[j],'l[k]',l[k],'cnt',cnt)
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
import math
n = int(input())
ls = list(input() for i in range(n))
a = []
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(ls[j])
    t.sort()
    m = " ".join(t)
    a.append(m)
c = collections.Counter(a)
for k in range(len(c)):
    b += combinations_count(c.most_common()[k][1], 2)
print(b)

Submission status: Runtime Error

Solution code:
from math import factorial

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

for j in range(len(S)):
  S[j].sort()
S.sort()
count=0
count_1=0
for k in range(len(S)):
  count=S.count(S[k])
  if count!=1:
    T = factorial(count) / factorial(2) / factorial(count-2)
    count_1 +=T/count
print(count_1)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
ans = 0
for count in Counter(s).values():
    ans += comb(count, 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from collections import defaultdict

n = int(input())
d = defaultdict(list)
d_num = defaultdict(int)
for _ in range(n):
    s = input()
    c = Counter(s)
    if _ == 0:
        d[s] = c
    for i,x in enumerate(d.keys()):
        flag = 0
        if d[x] == c:
            d_num[x] += 1
            break
        elif i == len(d.keys())-1:
            flag = 1
    if flag == 1:
        d[s] = c
        d_num[s] += 1
        
        ans = 0
for x in d_num.values():
    ans += x*(x-1)//2
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
count = 0
ans = 0
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count += ord(s[j])
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())

for i in newlis:
  ans += i*(i-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
def resolve():
    n = int(input())
    dict = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s[i] in dict.keys():
            dict[s] += 1
        else:
            dict[s] =1
    alist = list (dict.values())
    ans = 0
    for i in range(len(alist)):
        ct = alist[i]
        ans += (ct*(ct-1))//2
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
S=[]
ans=0
for i in range(N):
  s=sorted(input())
  S.append(s)
c=collections.Counter(S)
for i in set(S):
  n=c[i]
  ans+=(n*n-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
ans=0
S=[]
for i in range(N):
  s=input()
  S.append(sorted(s))
t=len(set(S))
if t==N:
  print("0")
else:
  print(N-t+1)

Submission status: Runtime Error

Solution code:
import collections
import math
n=int(input())
s=[''.join(list(input()).sort()) for _ in range(n)]
l=list(collections.Counter(s).values())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=0
for i in range(len(l)):
    k=int(l[i])
    if k!=1:c+=combinations_count(k,2)
print(c)

Submission status: Runtime Error

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

l=collections.Counter(s).values()
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=0
for i in range(len(l)):
    if l[i]!=1:c+=combinations_count(l[i],2)
print(c)

Submission status: Runtime Error

Solution code:
import collections
import math
n=int(input())
s=[''.join(list(input()).sort()) for _ in range(n)]
l=collections.Counter(s).values()
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=0
for i in range(len(l)):
    if l[i]!=1:c+=combinations_count(l[i],2)
print(c)

Submission status: Runtime Error

Solution code:
import math
import sys
input = sys.stdin.readline
N=int(input())
d={}
for i in [0]*N:
 s = ''.join(sorted(input().strip()))
 if s in d:
  d[s]+=1
 else:
  d[s]=1
e=0
for v in d.values():
 if v>=2:
  e+=int(math.factorial(v)/2)
print(e)

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}
from collections import Counter
for i in range(n):
  s = list(input())
  s = sorted(s)
  if s not in dic: dic[s] = 1
  else: dic[s] += 1
a = dic.values()
ans = 0
for i in range(len(a)):
  ans += a[i]*(a[i]-1)/2
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
counters = {}
from collections import Counter
for i in range(n):
  s = input()
  c = Counter(s)
  if c not in counters: counters[c] = 1
  else: counters[c] += 1
a = counters.values()
ans = 0
for i in range(len(a)):
  ans += a[i]*(a[i]-1)/2
print(ans)

Submission status: Runtime Error

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import Counter

def c2s(c):
    s = ''
    for key, val in c:
        # print(key, val)
        s = f'{s}{key}{val}'
    # print(s)
    return s

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

def solve():
    n = II()
    S = [list(input()) for _ in range(n)]

    jisho = {}
    for s in S:
        c = sorted(Counter(s).items(), key=lambda x: x[0])
        # print(c)
        key = c2s(c)
        jisho[key] = jisho.setdefault(key, 0) + 1
    # print(jisho)
    ans = 0
    for val in jisho.values():
        ans = ans + choose2(val)

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import math

n = int(input())

check = {}
ans = 0

for _ in range(n):
    word = sorted(input())
    new_word = ''.join(list(sorted(word)))
    check.setdefault(new_word, 0)
    check[new_word] += 1

for k in check:
    if check[k] >= 2:
        ans += int(math.factorial(check[k])/2)

print(ans)

Submission status: Runtime Error

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

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
for i in range(N):
  s = S[i]
  if s == prev:
    ans += 1
  prev = s
  
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
SS = [input() for _ in range(N)]

STR_IN_S = [[[] for _ in range(11)] for _ in range(26)]

for i in range(N):
  S = SS[i]
  c = Counter(S)
  for j in range(26):
    s = chr(97+j)
    STR_IN_S[j][c[s]].append(i)
    
SAME = [set(range(N)) for _ in range(N)]

for i in range(26):
  for j in range(11):
    l = STR_IN_S[i][j]
	nl = set(l)
    for x in l:
      SAME[x] &= nl
  
ans = 0
for i in range(N):
  ans += len(SAME[i]) - 1
  
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
SS = [input() for _ in range(N)]

STR_IN_S = [[[] for _ in range(11)] for _ in range(26)]

for i in range(N):
  S = SS[i]
  c = Counter(S)
  for j in range(26):
    s = chr(97+j)
    STR_IN_S[j][c[s]].append(i)
    
SAME = [set(range(N)) for _ in range(N)]

for i in range(26):
  for j in range(11):
    l = STR_IN_S[i][j]
    for x in l:
      SAME[x] &= l
  
ans = 0
for i in range(N):
  ans += len(SAME[i]) - 1
  
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations as c
n, *d = map(sorted, open(0).read().split())
print(sum(d[i[0]] == d[i[1]] for i in c(range(int(*n)), 2)))

Submission status: Runtime Error

Solution code:
def f(n):
  return (n**2-n)//2
ans=0
N=int(input())
d=dict()
for i in range(N):
  s=sorted(input())
  if s not in d:
    d[s]=0
  d[s]+=1
for i in d:
  ans+=f(i)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def String_Sort(str):
    tmp = sorted(str)
    ans = ""
    for i in tmp:
        ans += i
    return ans

def sol(n):
    return math.factorial(n) / 2

# main
li = []
n = int(input())
ans = 0
for i in range(n):
    li.append(String_Sort(input()))
li.sort()
# temporary
str = li[0]
num = 0
for i in li:
    if (i == str):
        num += 1
        continue
    else:
        if num>1:
            ans += sol(num)
        num = 1
        str = i
if (num > 1):
    ans+=sol(num)
print(int(ans))

Submission status: Runtime Error

Solution code:
memo = {2:1}
def cmb2(n):
  if n in memo:
    return memo[n]
  memo[n] = cmb2(n-1) + n - 1
  return memo[n]
n = int(input())
ans = 0
sum = 0
ansdic = {}
for i in range(n):
  s = input()
  slist = [i for i in s]
  slist.sort()
  smoji = ','.join(slist)
  if smoji in ansdic:
    ansdic[smoji] += 1
  else:
    ansdic[smoji] = 1
for i in ansdic:
  if ansdic[i] > 1:
    sum += cmb2(ansdic[i])
print(sum)

Submission status: Runtime Error

Solution code:
import collections
import math

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

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

c = collections.Counter(s)
ans = 0
for value in c.values():
    ans += combinations_count(value, 2)
    
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
def cmb(n,r):
  a = factorial(n) / factorial(r) / factorial(n - r)
  return a
n = int(input())
slist = []
cnt = 0
for i in range(n):
  s = input()
  s = sorted(s)
  
  s = ''.join(s)
  slist.append(s)
sset = set(slist)
stup = tuple(sset)
for i in range(len(sset)):
  if slist.count(stup[i]) >= 2:
    cnt += cmb(slist.count(stup[i]),2)
print(int(cnt))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for _ in range(N):
    s = list(input().rstrip("\r\n"))
    s.sort()
    d["".join(s)] += 1
ans = 0

def count(v):
    if v == 0:
        return 0
    return v + count(v-1)
for k in d:
    ans += count(d[k]-1)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 18:54:16 2020

@author: Kanaru Sato
"""

n = int(input())
Dict = {}
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for _ in range(N)]
check_box = []
ans = 0
for s in S:
  s = sorted(s)
  s = ''.join(s)
  print(s)
  print(check_box)
  if s in check_box:
    ans += 1
  else:
    check_box.append(s)
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
s = [""] * N
for i in range(N):
	s[i] = list(input())
	s[i].sort()
s.sort()

st, count = 1, 0
for i in range(1, N):
	if s[i - 1] == s[i]:
		st += 1
	elif st > 2:
		count += math.factorial(st) / (2 * (st - 2))
		st = 1
	elif st == 2:
		count += 1
		st = 1
if st > 2:
	count += math.factorial(st) / (2 * (st - 2))
elif st == 2:
	count += 1

print(int(count))

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
c = Counter([sorted(input()) for _ in range(N)])
print(sum([(v*(v+1))//2 for v in c.values()]))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
A=[]
for i in range(N):
    x= sorted(list(input()))
    A.append(x)
B=collections.Counter(A)
ans = 0
for i in B.values():
    ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(N):
    for j in range(i+1,N:
        if(l[i] == l[j]):
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
s=[]
ans=0
for i in range(n):
  S=''.join(sorted(input()))
  s.append(S)

for i in range(len(set(s))):
  tmp = s.count(list(set(s))[i])
  if tmp==1:
    ans+=0
  else:
    ans+=math.factorial(tmp)/math.factorial(2)*math.factorial(tmp-2)
  
print(int(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
d={}
ans=0
for _ in range(N):
  s=input()
  s=sortde(s)
  if s in d:
    d[s]+=1
  else:
    d[s]=0
for i in d.value():
  ans+=(int(i)**2+int(i))/2
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
words = dict()
count = 0
for i in range(n):
  s = sorted(input())
  if s in words:
    count += words[s]
    words[s] += 1
  else:
    words[s] = 0
print(count)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in s]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Submission status: Runtime Error

Solution code:
from math import factorial
def cmb(m,r):
  return factorial(m)//(factorial(r)*factorial(m-r))
n=int(input())
s=[input() for i in range(n)]
s.sort()
cnt=0
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=cmb(cnt+1,2)
    cnt=0
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
def cmb(n,r):
  return factorial(n)//(factorial(r)*factorial(n-r))
n=int(input())
s=[input() for i in range(n)]
s.sort()
cnt=0
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=cmb(cnt+1,2)
    cnt=0
print(ans)

Submission status: Runtime Error

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

from collections import Counter
from math import factorial

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += factorial(n) / factorial(2) / factorial(n - 2)
        
print(int(ans))

Submission status: Runtime Error

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

from collections import Counter
from math import factorial

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] != 1:
        n = values[i]
        ans += factorial(n) / factorial(2) / factorial(n - 2)
        
print(int(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
for i in range(N):
  s=list(sorted(input()))
  s=sorted(s)
n=s[0]
m=0
for j in range(1,N):
  if n==s[j]:
    m+=1
    n=s[j]
 print(m)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
n=list[0]
for j in range(N-1):
  if n==list[j+1]:
    t+=1
    n=list[j+1]
  else:
    t=t
    n=list[i+1]
print(t)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
t=0
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
n=list[0]
for j in range(N-1):
  if n==list[j+1]:
    t+=1
    n=list[j+1]
  else:
    n=list[i+1]
print(t)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
t=0
while list[i]==list[i+1] for i in range(N-1):
    t+=1
else:
    t=t
print(t)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
t=0
while all(list[i]==list[i+1] for i in range(N-1)):
    t+=1
  else:
    t=t
print(t)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
  list=list(sorted)
t=0
for i in range(N-1):
  if list[i]==list[i+1]:
    t+=1
print(t)

Submission status: Runtime Error

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=s.sort()
  l.append(s)
t=0
for i in range(N-1):
  for j in range(i+1,N):
    if l[i]==l[j]:
      t+=1
print(t)

Submission status: Runtime Error

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

lis=[collections.Counter(list(s[i])) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        if lis[i].items()==lis[j].items(): cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import itertools
from math import factorial


def combination_count(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


def main():

    n = int(input())
    words_list = []
    for _ in range(n):
        sorted_word = ''.join(sorted(input()))
        words_list.append(sorted_word)
    words_set = set(words_list)

    anagram_pair_count_all = 0
    for word in words_set:
        anagram_pair_count = words_list.count(word)
        anagram_pair_count_all += combination_count(anagram_pair_count, 2)

    print(anagram_pair_count_all)

    return 0


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8

def main():
  import math
  n = int(input())
  myset = set()
  mylist = list()
  mylist2 = list()
  
  for _ in range(n):
    sent = sorted(input())

    myset.add(''.join(sent))
    mylist.append(''.join(sent))
    
  for i in myset:
      a = mylist.count(i)
      mylist2.append(math.factorial(a)//(math.factorial(a-2)*2))
  
  print(sum(mylist2))
  
  return 0


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
nCr = {}
def cmb(n, r):
  if r == 0 or r == n: return 1
  if r == 1: return n
  if (n,r) in nCr: return nCr[(n,r)]
  nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
  return nCr[(n,r)]

d = {}
for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    d[l[i]] += 1
#print(d)
    
ans = 0
for a in d.values():
  #print(a)
  if a > 1:
    ans += cmb(a,2)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

d = {}
for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    d[l[i]] += 1

ans = 0
for a in d.values():
  if a > 1:
    ans += cmb(a,2)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

def annagram(s1: str, s2: str) -> bool:
    for i in range(10):
        if s1[i] != s2[i]:
            return False
    return True


ans: int = 0
for i in range(n-1):
    for j in range(i+1, n):
        if annagram(ss[i], ss[j]):
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = []
count = 0
for i in range(N):
  for j in range(i+1, N):
    if Counter(S[i]) == Counter(S[j]):
      count += 1
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = list(map(str,input().split()))
count = 0
for i in range(N):
  for j in range(i+1, N):
    if Counter(S[i]) == Counter(S[j]):
      count += 1
    else:
      break
print(count)

Submission status: Runtime Error

Solution code:
Lily
from collections import defaultdict

n = int(input())
dct = defaultdict(int)

for i in range(n):
    s = input()
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
from collections import OrderedDict

def solve(n, S):
    total = 0
    l = {}
    for s in S:
        key = ''.join(sorted(s))
        l[key] = (l[key] + 1) if key in l else 1
    for v in l.values():
        if v > 1:
            total += int(factorial(v) / factorial(2) / factorial(v - 2))
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))

Submission status: Runtime Error

Solution code:
N = int(input())

S = []
for _ in range(N):
    tmp=sorted(input())
    S.append(tmp)

S.sort()

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

import collections
from math import factorial

c = collections.Counter(S)

res=0
for v in c.values():
    if v>1:
        res += factorial(v) / factorial(2) / factorial(v - 2)

print(int(res))

Submission status: Runtime Error

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

def f(k):
  return k*f(k-1) if k>1 else 1
def c(n, k):
  return f(n)//(f(n-k)*f(k)) if n>=k else 0

print(sum(c(l.count(a), 2) for a in s))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())
dct = defaultdict(int)

for i in range(n):
    s = input()
    sorted_s = ''.join(sorted(s))
    dict[sorted_s] += 1

ans = 0
for a, b in dct.items():
    ans += b *(b-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
import math

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


n = int(input())
L = []
S = set()
count = 0
for i in range(n):
    line = "".join(sorted(list(input())))
    L.append(line)
    S.add(line)


for s in S:
    count += comb(L.count(s), 2)

print(count)

Submission status: Runtime Error

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1

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

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.values:
        if i < 2:
            continue
        else:
            res += i * (i-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()