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:
def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))

for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
cnt = 1
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i
    
if cnt >= 2:
    total += factorial(cnt)*factorial(cnt-2)/2

print(int(total))

Submission status: Runtime Error

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))

for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
cnt = 1
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i
total += factorial(cnt)*factorial(cnt-2)/2

print(int(total))

Submission status: Runtime Error

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))

for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
cnt = 1
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))

def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))

Submission status: Runtime Error

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))

Submission status: Runtime Error

Solution code:
import fractions

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += fractions.factorial(cnt)*fractions.factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += math.factorial(cnt)*math.factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()

s.sort()

tmp = 'a'
total = 0
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += math.factorial(cnt)*math.factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total)

Submission status: Runtime Error

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"


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

Submission status: Runtime Error

Solution code:
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(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(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp = "".join(sorted(tmp))
  s.append(tmp)
 
a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a[i] = x
 
# print("s:", s)
ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp = "".join(sorted(tmp))
  s.append(tmp)
 
a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
 
# print("s:", s)
ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a[i] = x

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a[i] = x

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp = "".join(sorted(tmp))
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a.append(x)

# print("s:", s)
ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**5):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

Submission status: Runtime Error

Solution code:
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():
    ans += C(i,2)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input().split())
dic={}
for i 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(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
for i in range(0,n):
  s=input().split()
  s[i]=''.join(sorted(s))
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(str,input().split()))
li=[0]*n
ans=0
for i in range(0,n):
  li[i]=''.join(sorted(s[i]))
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(str,input().split()))
li=[0]*n
ans=0
for i in range(0,n):
  li[i]=sorted(s[i])
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(input().split()))
li=[0]*n
ans=0
for i in range(0,n):
  li[i]=sorted(s[i])
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

li=[0]*n
ans=0
for i in range(0,n):
  s=list(input().split())
  li[i]=sorted(s[i])
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(input().split()))
li=[0]*n
ans=0
for i in range(0,n):
  li[i]=sorted(s[i])
for j in range(0,n):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
      
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import fractions
N = int(input())
s=[0]*N
S = []
for i in range(N):
    s_sorted =''.join(map(str, sorted(str(input()))))
    S.append(s_sorted)
c = Counter(S)
dic = {k: v for k, v in c.items() if v != 1}
if dic == {}:
    print(0)
else:
    ans = 0
    for i in range(len(list(dic.values()))):
        ans = ans+math.factorial(list(dic.values())[i])/math.factorial(2)/math.factorial(list(dic.values())[i]-2)
    print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
import fractions

N = int(input())
s=[0]*N
S = []
mydict = {}
flag=0
for i in range(N):
    s_sorted =''.join(map(str, sorted(str(input()))))
    S.append(s_sorted)
c = Counter(S)
dic = {k: v for k, v in c.items() if v !=1}
if dic == {}:
    print(0)
else:
    ans =0
    for i in range(len(list(dic.values()))):
        ans = ans+math.factorial(list(dic.values())[i])/math.factorial(2)/math.factorial(list(dic.values())[i]-2)
    print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
import fractions

N = int(input())
s=[0]*N
S = []
mydict = {}
flag=0
for i in range(N):
    s_sorted =''.join(map(str, sorted(str(input()))))
    S.append(s_sorted)
c = Counter(S)
dic = {k: v for k, v in c.items() if v !=1}
if dic == {}:
    print(0)
else:
    ans =0
    for i in range(len(list(c.values()))):
        ans = ans+math.factorial(list(dic.values())[i])/math.factorial(2)/math.factorial(list(dic.values())[i]-2)
    print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
import fractions

N = int(input())
s=[0]*N
S = []
mydict = {}
flag=0
for i in range(N):
    s_sorted =''.join(map(str, sorted(str(input()))))
    S.append(s_sorted)
c = Counter(S)
ans =0
for i in range(len(list(c.values()))):
    ans = ans+math.factorial(list(c.values())[i])/math.factorial(2)/math.factorial(list(c.values())[i]-2)
print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
s = {}
total = 0

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

for i in s:
    if i != 1:
        total += sum([i for i in range(1,i)])

print(total)

Submission status: Runtime Error

Solution code:
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
      
n = int(input())
sn = {}
sn_list = []
for i in range(n):
    s = input()
    sn_list.append(s)
for s in sn_list:
    s = "".join(sorted(s))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1

count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)

n = int(input())
sn = {}
sn_list = []
for i in range(n):
    s = input()
    sn_list.append(s)
for s in sn_list:
    s = "".join(sorted(s))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
        
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
      
      
n = int(input())
sn = {}
sn_list = []
for i in range(n):
    s = "".join(sorted(input()))
    sn_list.append(s)
for s in sn_list:
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
        
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
sn = {}
for i in range(n):
    s = "".join(sorted(input()))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
      
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
sn = {}
for i in range(n):
    s = "".join(sorted(input()))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)
      
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
def sigma(c):
    if c == 1:
        return 1
    elif c == 0:
        return 0
    else:
        return c + sigma(c-1)

n = int(input())
sn = {}
for i in range(n):
    s = "".join(sorted(input()))
    if not(s in sn):
        sn[s] = 0
    else:
        sn[s] += 1
        
count = 0
for v in sn.values():
    count += sigma(v)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
dic = {}
plis = [2]
for i in range(3,100):
    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)

Submission status: Runtime Error

Solution code:
n=int(input())

L=list(map(int,sorted(input().split())))

L=sorted(L)
from scipy.speial import comb
k=1
sum=0
for i in range(n-1):
  if L[i]==L[i+1]:
    k += 1
  else:
    if k==1:
      sum +=1
    else:
      sum += comb(k,2,exact=True)
    k=1
if k==1:
  sum += 1
else:
  sum += comb(k,2,exact=True)
print(sum)

Submission status: Runtime Error

Solution code:
from math import factorial


def comb(n, r):
    if n == 0 or n-r < 0:
        return 0
    return int(factorial(n) / factorial(r) / factorial(n-r))


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

S.sort()

count = 0
count_min = 0
tmp = []
for s in S:
    if s == tmp:
        count_min += 1
    else:
        count += comb(count_min+1, 2)
        count_min = 0
    tmp = s
    # print('count:{}, min:{}'.format(count, count_min))
count += comb(count_min+1, 2)
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial


def comb(n, r):
    if n == 0 or n-r < 0:
        return 0
    return factorial(n) / factorial(r) / factorial(n-r)


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

S.sort()

count = 0
count_min = 0
tmp = []
for s in S:
    if s == tmp:
        count_min += 1
    else:
        count += comb(count_min+1, 2)
        count_min = 0
    tmp = s
    # print('count:{}, min:{}'.format(count, count_min))
count += comb(count_min+1, 2)
print(int(count))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

S.sort()

count = 0
count_min = 0
tmp = []
for s in S:
    if s == tmp:
        count_min += 1
    else:
        count += comb(count_min+1, 2, exact=True)
        count_min = 0
    tmp = s
    # print('count:{}, min:{}'.format(count, count_min))
count += comb(count_min+1, 2, exact=True)
print(count)

Submission status: Runtime Error

Solution code:
# ABC137C - Green Bin
from collections import Counter


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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
	s.append("".joint(sorted([a for a in input()])))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

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 #2個の場合は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)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
di = dict()
answer = 0

for i in range(n):
    tmp = str(sorted(input()))
    if di.get(tmp, 0) == 0:
        di[tmp] = 1
    else:
        di[tmp] += 1

for v in di.values():
    if v > 1:
        answer += int(math.factorial(v) / 2)
print(answer)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
di = dict()
answer = 0

for i in range(n):
    tmp = str(sorted(input()))
    if di.get(tmp, 0) == 0:
        di[tmp] = 1
    else:
        di[tmp] += 1

for v in di.values():
    if v > 1:
        answer += (math.factorial(v) / 2)
print(answer)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
di = dict()
answer = 0

for i in range(n):
    tmp = str(sorted(input()))
    if di.get(tmp, 0) == 0:
        di[tmp] = 1
    else:
        di[tmp] += 1

for v in di.values():
    if v > 1:
        answer += int(math.factorial(v) / 2)
print(answer)

Submission status: Runtime Error

Solution code:
from sys import stdin, exit
from math import factorial
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

def choose(x):
  return factorial(x)/(2*factorial(x-2))

words = {}

for i in range(int(input())):
    s = "".join(sorted(si()))
    if s not in words:
        words[s] = 1
    else:
        words[s] += 1
ans = 0
print(words)
for i in words:
    ans += choose(words[i])
print(int(ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

if __name__ == '__main__':

	n = int(input())

	dic = {}
	for _ in range(n):

		new_str = ''.join(sorted(list(input())))

		if new_str not in dic:
			dic[new_str] = 1
		else:
			dic[new_str] += 1

	total_cnt = 0
	for value in dic.values():
		if value == 2:
			total_cnt += 1
		elif value >= 3:
			total_cnt += comb(value, 2, exact=True)

	print(total_cnt)

Submission status: Runtime Error

Solution code:
from math import factorial

if __name__ == '__main__':

	n = int(input())

	dic = {}
	for _ in range(n):

		new_str = ''.join(sorted(list(input())))

		if new_str not in dic:
			dic[new_str] = 1
		else:
			dic[new_str] += 1

	total_cnt = 0
	for value in dic.values():
		if value == 2:
			total_cnt += 1
		elif value >= 3:
			total_cnt += factorial(value) / factorial(2) / factorial(value - 2)

	print(int(total_cnt))

Submission status: Runtime Error

Solution code:
from collections import Counter
#from math import factorial
from scipy.special import comb
def com(n , r):
    return factorial(n) // (factorial(n - r) * factorial(r))
N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append("".join(sorted(s)))
CS = Counter(S)
ans = 0
for val in CS.values():
    ans += comb(val , 2 , exact = True)
print(ans)

Submission status: Runtime Error

Solution code:
size = int(input())
li = []
c = 0 
for _ in range(size):
  a = input()
  li.append(a)
  for i in range(0,size):
    for j in range(i,size):
      if sorted(li[i])==sorted(li[j]):
        c += 1
  print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
S =[[] for _ in range(N)]
for i in range(N):
  s = list(str(input()))
  s.sort()
  s = ''.join(s)
  S[i].append(s)
from collections import Counter
l = Counter(S)
count = []
for i in l.values:
  count.append(i*(i-1)/2)
print(sum(count))

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}　#空の辞書を定義
def combinations_count(n,r):
    return math.factorial(n) // (math.factorial(n - r)*math.factorial(r))

for index in range(n):
    temp = ''.join(sorted(list(input())))
    #入力された文字列をa-z順にソートし、変数tempに代入
    if temp in dic:
        dic[temp] = dic[temp] + 1
        #すでに同じ文字列の入力があれば、key:tempのvalueに+1
    else:
        dic[temp] = 1
        #新しい文字列の場合は文字列とvalue＝1を辞書に追加
ans = 0

for k in dic.values():
    ans += combinations_count(k,2)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}　#空の辞書を定義

for index in range(n):
    temp = ''.join(sorted(list(input())))
    #入力された文字列をa-z順にソートし、変数tempに代入
    if temp in dic:
        dic[temp] = dic[temp] + 1
        #すでに同じ文字列の入力があれば、key:tempのvalueに+1
    else:
        dic[temp] = 1
        #新しい文字列の場合は文字列とvalue＝1を辞書に追加
ans = 0

for k in dic.values():
    cnt = 0
    for i in range(k):
        cnt += i
    ans += cnt
print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define CS
long long int ll;
using namespace std;
int main(){
    speed;
    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    int sum=0,cnt=1;
    for(int i=1;i<n;i++)
    {
        if(v[i]==v[i-1])
            cnt++;
        else
        {
            sum+=((cnt-1)*cnt)/2;
            cnt=1;
        }
    }
    sum+=((cnt-1)*cnt)/2;
    cout<<sum<<endl;
}

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
lst=[]
for i in range(n):
  s=input()
  lst.append(s)
for i in lst:
  ans+=lst.count(i)
  del(lst[lst.index(i)]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

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

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()

len_C = len(C)

for n in range(len_C):
    if C[n][1] == 1:
        del C[n]
    else:
        pass

len_C = len(C)

for m in range(len_C):
    ans += combination(C[m][1], 2)

print(round(ans))

Submission status: Runtime Error

Solution code:
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

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

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

print(Y)

c = collections.Counter(Y)
C = c.most_common()

len_C = len(C)
print(C)
print(len_C)

for n in range(len_C):
    if C[n][1] == 1:
        del C[n]
    else:
        pass
print(C)

len_C = len(C)

for m in range(len_C):
    ans += combination(C[m][1], 2)

print(round(ans))

Submission status: Runtime Error

Solution code:
from sys import stdin

N = int(stdin.readline())
letter = 26

s = []
vec = []
for i in range(N):
    temp = input()
    s.append(temp)
    temp_list = [0 for i in range(letter)]
    for j in temp:
        temp_list[ord(j)-97]+=1
    vec.append(temp_list)

count = 0
for i in range(N):
    for j in range(i+1, N):
        if vec[i] == vec[j]:
            count += 1
            vec[j].pop()

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

b = [False]*n
ans = 0
count = 1

for i in range(n):
  if b[i]:
    continue
  for j in range(i+1, n):
    if ana(s[i], s[j]):
      count += 1
      b[j] = True
  ans += count * (count-1) / 2
  count = 1
  b[i] = True
  
print(ans)
  
def ana(s1, s2):
  b = [False] * len(s1)
  for i in range(len(s1)):
    for j in range(len(s2)):
      if b[j]:
        continue
      if s1[i] == s2[j]:
        b[j] = True
  for i in range(len(s1)):
    if not b[i]:
      return False
  return True

Submission status: Runtime Error

Solution code:
N=int(input())
LST=[]
for i in range(N):
    a=input()
    lst=[]
    for j in range(len(a)):
        lst.append(a[j])
    lst=sorted(lst)
    if lst in LST:
        count+=1
        break
    else:
        LST.append(lst)
        

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())

# alp = ["a","b","c","d","e",
# "f","g","h","i","j",
# "k","l","m","n","o",
# "p","q","r","s","t",
# "u","v","w","x","y","z"]
#
ans = 0
# array1 = np.zeros().reshape( n,10)


# list1 = []
list_s = []

for i in range(n):
    s = input()
    s.sort()
    ans += list_s.count(s)

    list_s.append(s)

print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += factorial(c) / 2
print(int(t))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

import collections

n = int(input())

arr = []

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

c = collections.Counter(arr)

ans = 0

for e in c.values():
    ans += comb(e, 2, exact=True)


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [sorted(input()) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict(s[i])
        s_dict(s[i]) += 1
    else:
        s_dict(s[i]) = 1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        s_dict(s[i]) += 1
        sum += s_dict(s[i])
    else:
        s_dict(s[i]) = 1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [sorted(input()) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        s_dict(s[i]) += 1
        sum +=s_dict(s[i])
    else:
        s_dict(s[i]) = 1
print(sum)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N; cin >> N;

    vector<string> s(N+10); rep(i,N) cin >> s[i];

    vector<int> alp(26, 0);

    string t;

    map<string,int> m;

    int ans = 0;

    rep(i,N)
    {
        rep(j,26) alp[j] = 0;
        t = "";

        rep(j,10)
        {
            alp[(int)s[i][j] - (int)'a']++;
        }
        rep(j,26)
        {
            rep(k,alp[j]) t += (char)(j+(int)'a');
        }

        if (m.find(t) != m.end()) m[t]++;
        else m[t] = 1;
    }

    int n;
    for (auto x: m)
    {
        n = x.second;
        ans += n * (n-1) / 2;
    }

    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
d = {}
for i in range(n):
  a = input();k = 0
  for j in range(10):
    k+= ord(a[j]) - 95
  if k not in d:
    d[k] = 1
  else:
    d[k]+=1
if len(d) == 0:
  print(0)
else:
  print(max(d.values())

Submission status: Runtime Error

Solution code:
import math

N=int(input())
S=[]
for i in range(N):
    s=input()
    ss=list(s)
    ss.sort()
    S.append(ss)
S.sort()
ans=0
cnt=0
for i in range(N-1):
    if S[i]==S[i+1]:
        cnt+=1
    else:
        ans+=math.factorial(cnt-1)
        cnt=0
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
k = 0
for i in range(N - 1) :
    for j in range(i + 1, N) :
        if s[i] == s[k] :
            k += 1
print(k)

Submission status: Runtime Error

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

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            ans += 1
            S.pop(j)
            break
        break
print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            ans += 1
            S.pop(j)
            break
print(ans)