TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
N=int(input())


S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L




N=int(input())


S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L

S.sort()

goukei=0
banpei=S[0]
ncr=1
for i in range(1,N):
    if banpei==S[i]:
        ncr+=1
    else:
        if ncr>=2:
            goukei+=(ncr*(ncr-1))//2
        ncr=1
        banpei=S[i]

if ncr>=2:
    goukei+=(ncr*(ncr-1))//2 
    

print(goukei)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
n = int(input())
seen = defaultdict(int)
for _ in range(n):
  s = sorted(input())
  seen[s]+=1

ans = 0
for i in seen:
  ans+= seen[i]*(seen[i]-1)//2
print(ans)

from collections import defaultdict
n = int(input())
seen = defaultdict(int)
for _ in range(n):
  s = "".join(sorted(input()))
  seen[s]+=1

ans = 0
for i in seen:
  ans+= seen[i]*(seen[i]-1)//2
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
amap = {}
cnt = 0
n = int(input())
for i in range(n):
  s = "".join(sorted(input()))
  if s in amap:
    cnt += amap[s]
  amap[s] += 1

print(cnt)

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

print(cnt)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
d={}
s=0
for _ in range(int(input())):
  l=input()
  l=sorted(l)
  f=d.keys()
  if l not in f:
    d[l]=0
  else:
    d[j]+=1
    s+=d[j]
print(s)
    
    
  

def areAnagram(str1, str2):  
    # Get lengths of both strings  
    n1 = len(str1)  
    n2 = len(str2)  
    
      
    if n1 != n2:  
        return 0
  
     
    str1 = sorted(str1) 
    str2 = sorted(str2) 
  
      
    for i in range(0, n1):  
        if str1[i] != str2[i]:  
            return 0
  
    return 1
n=int(input())
l=[]
for i in range(n):
  l.append(input())
s=0
for i in range(n):
  for j in range(i,n):
    if areAnagram(l[i],l[j]):
      s+=1
print(s)

d={}
s=0
for _ in range(int(input())):
  l=input()
  l=str(sorted(l))
  f=d.keys()
  if l not in f:
    d[l]=0
  else:
    d[l]+=1
    s+=d[l]
print(s)
    

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
s = [0]*N
p = [0]*N
for i in range(N):
    s[i] = "".join(sorted(input()))
    print(s)
    for j in range(i-1,-1,-1):
        if s[i] == s[j]:
            p[i] = p[j] + 1
            break

print(sum(p))

n = int(input)
ans = {}
for i in range(n):
    s = input()
    t = []
    for i in range(len(s)):
        t.append(s[i])
    t.sort()
    k = "".join(t)
    if k in ans:
        ans[k] = ans[k]+1
    else:
        ans[k] = 0
answer = 0
for i in ans:
    j = ans[i]
    answer += j*(j+1)//2
print(answer)

n = int(input())
ans = {}
for i in range(n):
    s = input()
    t = []
    for i in range(len(s)):
        t.append(s[i])
    t.sort()
    k = "".join(t)
    if k in ans:
        ans[k] = ans[k]+1
    else:
        ans[k] = 0
answer = 0
for i in ans:
    j = ans[i]
    answer += j*(j+1)//2
print(answer)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    list = []
    result = 0
    N = int(input())
    for i in range(0, N):
        ss = input()
        s = "".join(sorted(ss))
        if i == 0:
            list.append(s)
        else:
            for j in list:
                if j == s:
                    result += 1
                    break
                list.append(s)
    print(result)


if __name__ == '__main__':
    main()

def main():
    word = {}
    n = int(input())
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in word:
            word[s] += 1
        else:
            word[s] = 1
    answer = 0
    for cnt in word.values():
        answer += cnt * (cnt - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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))
  



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


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

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

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

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


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

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

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


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

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":57, "r":59, "s":61, "t":67, "u":71, "v":73, "w":79, "x":83, "y":87, "z":1}

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

for s in S:
    s = np.prod([D[x] for x in s])
    if s in S:
        n_anagram = n_anagram + S[s]
        S[s] += 1
    else:
        S[s] = 1
    
print(n_anagram)

import numpy as np
N = input()

N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":57, "r":59, "s":61, "t":67, "u":71, "v":73, "w":79, "x":83, "y":89, "z":1}

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

for s in S:
    s1 = [D[x] for x in s]
    print(s1)
    s2 = np.prod(s1)
    print(s2)
    if s2 in Sdict:
        n_anagram = n_anagram + Sdict[s2]
        Sdict[s2] += 1
    else:
        Sdict[s2] = 1
   
print(n_anagram)

import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":59, "r":61, "s":67, "t":71, "u":73, "v":79, "w":83, "x":89, "y":97, "z":1}

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

for s in S:
    s1 = [D[x] for x in s]
    s2 = np.prod(s1)

    if s2 in Sdict:
        n_anagram = n_anagram + Sdict[s2]
        Sdict[s2] += 1
    else:
        Sdict[s2] = 1
   
print(n_anagram)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
count = 0
DIC = {}
for i in range(n):
    j = ''.join(sorted(input()))
    if j in DIC:
        count += DIC[j]
        DIC[j] += 1
    else:
        DIC[j] = 1
print(count)


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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

import collections
n=int(input())
s=collections.Counter(["".join(sorted(input())) for _ in range(n)])
v=list(s.values())
res=0
for u in v:
	if u!=1:
		res += u*(u-1)//2
print(res)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: UTF-8 -*-

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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()
print(l)

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)


# -*- coding: UTF-8 -*-
import math

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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 0
f = 0

for i in range(n):
    if l[i] == l[i+1]:
        s =+ 1
        f = 1
    elif l[i] != l[i+1] and f == 1:
        s += 1
        f = 0
        p += math.factorial(s)/(2 * math.factorial(s-2))


print(p)


# -*- coding: UTF-8 -*-

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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()
print(l)

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s =+ 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += s * (s-1) / 2
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)


# -*- coding: UTF-8 -*-

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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

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


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)

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)


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)

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)

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)


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)

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)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
anagram(N,S)

def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
print(anagram(N,S))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin


def main():
    N = int(stdin.readline())
    s = [stdin.readline().rstrip().split() for _ in range(N)]

    s_flat = [flatten for inner in s for flatten in inner]

    s_dict = {}
    sum = 0

    for S in s_flat:
        new_S = ''.join(sorted(S))
        print(new_S)
        if not s_dict.get(new_S):
            s_dict[new_S] = 1
        else:
            sum += s_dict[new_S]
            s_dict[new_S] = s_dict[new_S] + 1

    print(sum)


if __name__ == "__main__":
    main()


from sys import stdin


def main():
    N = int(stdin.readline())
    s = [stdin.readline().rstrip().split() for _ in range(N)]

    s_flat = [flatten for inner in s for flatten in inner]

    s_dict = {}
    sum = 0

    for S in s_flat:
        new_S = ''.join(sorted(S))
        if not s_dict.get(new_S):
            s_dict[new_S] = 1
        else:
            sum += s_dict[new_S]
            s_dict[new_S] = s_dict[new_S] + 1

    print(sum)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]
#print(texts)
c=collections.Counter(texts)
print(sum(c.values()))

import collections
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]
#print(texts)
c=collections.Counter(texts)
#print(c)
ans=sum([i*(i-1)/2 for i in c.values()])
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict


def solve(string):
    n, *s = string.split()
    d = defaultdict(int)
    for _s in s:
        d["".join(sorted(_s))] += 1
    return str(sum([v * (v - 1) // 2 for v in d.values() if v > 1]))


if __name__ == '__main__':
    print(solve(input()))


def solve(string):
    n, *ss = string.split()

    d = defaultdict(int)
    for s in ss:
        s = "".join(sorted(s))
        if s in d.keys():
            d[s] += 1 + d[s]
    return str(sum(d.values()))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


def solve(string):
    n, *ss = string.split()
    d = {}
    for s in ss:
        s = "".join(sorted(s))
        d[s] = 1 + d[s] if s in d.keys() else 0
    return str(sum([v * (v - 1) // 2 for v in d.values()]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


from collections import Counter


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


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())

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

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

n = int(input())

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

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
print(S)
prev = ''
ans = 0
n = 0
for i in range(N):
    if S[i]!=prev:
        ans += n*(n-1)//2
        prev=S[i]
        n=1
    else:
        n+=1
ans += n*(n-1)//2

print(ans)

N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
prev = ''
ans = 0
n = 0
for i in range(N):
    if S[i]!=prev:
        ans += n*(n-1)//2
        prev=S[i]
        n=1
    else:
        n+=1
ans += n*(n-1)//2
 
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
n = int(input())
s = [input() for i in range(n)]
tmp = [defaultdict(int) for i in range(n)]

for j in range(len(s)):
    for k in s[j]:
        tmp[j][k] += 1
        
ans = 0
for i in range(0,len(s)):
    for j in range(i+1,len(s)):
        if(tmp[i]==tmp[j]):
            print(s[i])
            print(s[j])
            ans += 1
print(ans)

from collections import defaultdict
tmp = [defaultdict(int) for i in range(n)]
n = int(input())
s = [input() for i in range(n)]

for j in range(len(s)):
    for k in s[j]:
        tmp[j][k] += 1
        
ans = 0
for i in range(0,len(s)):
    for j in range(i+1,len(s)):
        if(tmp[i]==tmp[j]):
            print(s[i])
            print(s[j])
            ans += 1
print(ans)

from collections import defaultdict
dic = defaultdict(int)

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

ans = 0
for j in range(len(s)):
    mozi = sorted(s[j])
    mozi_s = "".join(mozi)
    ans += dic[mozi_s]
    dic[mozi_s] += 1
    
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
S=[input() for _ in range(n)]
S=[''.join(sorted(i)) for i in S]
d={}
rslt=0
for s in S:
    if s in d:
        rslt+=d
        d+=1
    else:
        d[s]=1
print(rslt)


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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter 
n = int(input())
anagram =[]
ans = 0
for _ in range(n):
    s = ''.join(input())
    anagram.append(s)
count_ana = Counter(anagram)
for v in count_ana.values():
    ans += v * (v + 1) // 2
print(ans)


n = int(input())
anagram =[]
ans = 0
for _ in range(n):
    s = ''.join(input())
    anagram.append(s)
count_ana = Counter(anagram)
for v in count_ana.values():
    ans += v * (v + 1) // 2
print(ans)

from collections import Counter 
n = int(input())
anagram =[]
ans = 0
for _ in range(n):
    s = ''.join(sorted(input()))
    anagram.append(s)
count_ana = Counter(anagram)
for v in count_ana.values():
    ans += v * (v - 1) // 2
print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
cnt = 0
s_dic = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in s_dic:
        s_dic[s] += 1
        cnt += s_dic[s]
    else:
        s_dic[s] = 1
        cnt += s_dic[s]

print(cnt)


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

print(cnt)


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

print(cnt)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
d=dict()
for i in range(n):
  l = "".join(sorted(input())) 
  if l not in d:
    d[l]=1
  else:
    d[l]+=1
ans=0
for x in d.values():
  ans+=(x*x-1)/2
print(ans)
  

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)


n=int(input())
d=dict()
for i in range(n):
  l = "".join(sorted(input())) 
  if l not in d:
    d[l]=1
  else:
    d[l]+=1
ans=0
for x in d.values():
  ans+=(x*x+1)/2
print(ans)
  

n=int(input())
d=dict()

for i in range(n):
  s="".join(sorted(input()))
  #print(s)
  if s in d:
    d[s]+=1
  else:
    d[s]=1
ans=0
for x in d.values():
  ans+=x*(x-1)//2
print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
S = [input() for _ in range(N)]

ans = 0
S = ["".join(sorted(s)) for s in S]

from collections import Counter

c = Counter(S)
print(c.most_common()[0][1])

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

cnt = 0
dic = {}

for w in S:
    if w in dic:
        cnt += dic[w]
        dic[w] += 1
    else:
        dic[w] = 1
        
print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)

N = int(input())
#print(N)
S=[]
for i in range(N):
    #print(i)
    S.append("".join(sorted(input())))
    # print(input())
S.sort()
#print(S)
n = 1
ans=0
for i in range(1,N):
    if S[i] == S[i-1]:
        n = n + 1
    else:
        #print(i,n)
        ans = ans + n * (n-1) //2 
        n = 1
ans = ans + n * (n-1) // 2


import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)

N = int(input())
#print(N)
S=[]
for i in range(N):
    #print(i)
    S.append("".join(sorted(input())))
    # print(input())
S.sort()
#print(S)
n = 1
ans=0
for i in range(1,N):
    if S[i] == S[i-1]:
        n = n + 1
    else:
        #print(i,n)
        ans = ans + n * (n-1) //2 
        n = 1
ans = ans + n * (n-1) // 2
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding:utf-8 -*-

import math

N = int(input())

type_dict = {}
for _ in range(N):
    s = input()
    counts = (
        s.count('a'), s.count('b'), s.count('c'), s.count('d'),
        s.count('e'), s.count('f'), s.count('g'), s.count('h'),
        s.count('i'), s.count('j'), s.count('k'), s.count('l'),
        s.count('m'), s.count('n'), s.count('o'), s.count('p'),
        s.count('q'), s.count('r'), s.count('s'), s.count('t'),
        s.count('u'), s.count('v'), s.count('w'), s.count('x'),
        s.count('y'), s.count('z')
    )
    if counts in type_dict:
        type_dict[counts] = type_dict[counts] + 1
    else:
        type_dict[counts] = 1


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


print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1]))


# -*- coding:utf-8 -*-

import math

N = int(input())

type_dict = {}
for _ in range(N):
    s = input()
    counts = (
        s.count('a'), s.count('b'), s.count('c'), s.count('d'),
        s.count('e'), s.count('f'), s.count('g'), s.count('h'),
        s.count('i'), s.count('j'), s.count('k'), s.count('l'),
        s.count('m'), s.count('n'), s.count('o'), s.count('p'),
        s.count('q'), s.count('r'), s.count('s'), s.count('t'),
        s.count('u'), s.count('v'), s.count('w'), s.count('x'),
        s.count('y'), s.count('z')
    )
    if counts in type_dict:
        type_dict[counts] = type_dict[counts] + 1
    else:
        type_dict[counts] = 1


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


print(sum([combinations_count(x, 2) for x in type_dict.values() if x > 1]))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
dict={}
for i in s:
  if i in dict:
    dict[i]+=1
    ans+=dict[i]
  else:
    dict[i]=1
print(ans)

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

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

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

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
S = [sorted(list(input())) for _ in range(N)]

ans = N
for i in range(N):
    for j in range(i+1, N):
        if S[i]==S[j]:
            ans -= 1
print(ans)

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

D = {}
ans = 0
for s in S:
    if s in D:
        D[s] += 1
        ans += D[s]
    else:
        D[s] = 0

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# 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()

# ABC137C - Green Bin
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()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
arr = [input() for i in range(n)]
listarr = [[arr[i][j] for j in range(10)] for i in range(n)]
for i in range(n):
    listarr[i].sort()
tuplearrsort = [tuple(listarr[i]) for i in range(n)]
dic = {}

for i in range(n):
    if tuplearrsort[i] in dic:
        dic[tuplearrsort[i]] += 1
    else:
        dic[tuplearrsort[i]] = 1
      
count = 0
for key in dic:
    if dic[key] == 1:
        count += 1
    else:
        count += (dic[key] * (dic[key]-1)) // 2
    
print(count)

n = int(input())
arr = [input() for i in range(n)]
listarr = [[arr[i][j] for j in range(10)] for i in range(n)]
for i in range(n):
    listarr[i].sort()
tuplearrsort = [tuple(listarr[i]) for i in range(n)]
dic = {}

for i in range(n):
    if tuplearrsort[i] in dic:
        dic[tuplearrsort[i]] += 1
    else:
        dic[tuplearrsort[i]] = 1
      
count = 0
for key in dic:
    count += (dic[key] * (dic[key]-1)) // 2
    
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
dic = { c: i for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')}

n = int(input())
strs = [tuple(sorted(map(lambda x: dic[x], input())))  for _ in range(n)]

a = {}
for s in strs:
  if s not in a:
    a[s] = 1
  else:
    a[s] += 1

print(a)
print(sum(item[1]*(item[1]-1)//2 for item in a.items()))

dic = { c: i for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')}

n = int(input())
strs = [tuple(sorted(map(lambda x: dic[x], input())))  for _ in range(n)]

a = {}
for s in strs:
  if s not in a:
    a[s] = 1
  else:
    a[s] += 1

print(sum(item[1]*(item[1]-1)//2 for item in a.items()))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
for i in range(num)
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for i in range(cnt):
        dic.remove(now)
    i += cnt - 1
print(ans)

num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
for i in range(num):
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for now in dic:
        dic.remove(now)
print(ans)

num = int(input())
li = [input() for i in range(num)]

dic = {}
ans = 0
for i in range(num):
    now = "".join(sorted(li[i]))
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
for i in dic:
    n = dic[i]
    ans += int((n*(n-1))/2)

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**7 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    while True:
        if h >= mod :
            h = 0
        if hs[h][0] == 0:
            hs[h][0] += 1
            hs[h][1] += s
            break
        if hs[h][1] == s:
            hs[h][0] += 1
            break
        h += 1

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(ans))



import sys
input = sys.stdin.readline

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**6 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    while True:
        if h >= mod :
            h = 0
        if hs[h][0] == 0:
            hs[h][0] += 1
            hs[h][1] += s
            break
        if hs[h][1] == s:
            hs[h][0] += 1
            break
        h += 1

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(ans))


Verdicts: Time Limit Exceeded

Accepted