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

N = int(input())
S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  w = "".join(s)
  S[w] += 1

print(S)
ans = sum([(i*(i-1))//2 for i in list(S.values())])

print(ans)

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))

from collections import defaultdict

N = int(input())
S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  w = "".join(s)
  S[w] += 1

ans = sum([(i*(i-1))//2 for i in list(S.values())])

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

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

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.setdefault(i, 1)
    else :
        cnt[string_counters.index(string)] += 1

output = 0
for k, v in cnt.items():
    output += combinations_count(v, 2)

print(output)


N = int(input())
cnt = dict()
output = 0

for i in range(N):
    string = ''.join(sorted(input()))
    cnt.setdefault(string, 0)
    output += cnt[string]
    cnt[string] += 1

print(output)

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= [input() for i in range(N)]
ans=0
dp = list(range(N))

for i in range(N):
        for k in range(i+1,N):
                if dp[i] == dp[k]:
                        ans += 1
                else:
                        A=list(sorted(s[i]))
                        for j in list(sorted(s[k])):
                                if j in A:
                                        A.remove(j)
                                else:
                                        break
                        if len(A) == 0:
                                ans += 1
                                dp[k]=min(dp[i],dp[k])
                                dp[i]=dp[k]
print(dp)
print(ans)


import math
def cmb(n, r):
        if r > n: 
                return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


import collections
N = int(input())
s= [input() for i in range(N)]
ans=0

s=list(map(sorted,s))

s.sort()        
s=list(map(''.join,s))  
clist = collections.Counter(s) 
kaisu=list(clist.values())

for i in kaisu:
        ans += cmb(i,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):
n = int(input())
buf = []
ans = 0

for i in range(n):
  lists = [i for i in input().split()]
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)  


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

for i in range(n):
  lists = input().split()
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)  

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

for i in range(n):
  lists = [j for j in input().split()]
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)  


#137-c
n = int(input())
buf = []

for i in range(n):
    s  = input()
    l = list(s)
    l.sort()
    sort_s = "".join(l)
    buf.append(sort_s)

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

ans += same*(same-1)//2
print(ans)

Verdicts: Wrong Answer

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 sys

Ans = 0
N = int(input())
S = []
T = []
U = []
for _ in range(N):
  S.append(str(input()))
T = ['a'] * N  
U = ['a'] * N

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

T = sorted(U)

j = 0
while j < N:
  for k in range(1,N):
    if j + k == N - 1:
      if T[j] != T[j + k]:
        Ans = Ans + (k*(k-1))/2
      else:
        Ans = Ans + (k*(k+1))/2
        
      print(Ans)
      sys.exit()
      
    if T[j] != T[j + k]:
      Ans = Ans + (k*(k-1))/2
      a = k
      break
  
  j = j + a


import sys
 
Ans = 0
N = int(input())
S = []
T = []
U = []
for _ in range(N):
  S.append(str(input()))
T = ['a'] * N  
U = ['a'] * N
 
for i in range(N):
  U[i] = ''.join(sorted(S[i]))
 
T = sorted(U)
 
j = 0
while j < N:
  for k in range(1,N):
    if j + k == N - 1:
      if T[j] != T[j + k]:
        Ans = Ans + (k-1) * k / 2
      else:
        Ans = Ans + (k+1) * k / 2
        
      print(int(Ans))
      sys.exit()
      
    if T[j] != T[j + k]:
      Ans = Ans + (k-1) * k / 2
      a = k
      break
  
  j = j + a
  
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):
n=int(input())
s={}
for i in range(n):
  tmp=list(input().strip()).sort()
  tmp="".join(tmp)
  s[tmp]=s.get(tmp,0)+1
  
ans=0
for key in s.keys():
  v=s[key]
  if v<2:
    continue
  cmb=v*(v-1)
  cmb=cmb//2
  ans+=cmb
print(ans)

n=int(input())
dic={}
for i in range(n):
  tmp="".join(sorted(list(input().strip())))
  dic[tmp]=dic.get(tmp,0)+1
ans=0
for k in dic.keys():
  if dic[k] >= 2:
    ans+=(dic[k]*(dic[k]-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):
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
data = []
for _ in range(n):
    s = input()
    data.append(count(s))
ans = 0
for i in range(n):
    for ii in range(i+1, n):
        if data[i] == data[ii]|:
            ans += 1
print(ans)



def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

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

ans = 0
for v in counts.values():
    ans += (v*(v-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):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
dic_s = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s in dic_s:
        dic_s[s] += 1
    else:
        dic_s[s] = 1
counter = 0
for key,value in dic_s.items():
    counter += combinations_count(value,2)
print(counter)

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

N = int(input())
dic_s = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s in dic_s:
        dic_s[s] += 1
    else:
        dic_s[s] = 1
counter = 0
for key,value in dic_s.items():
    if value >1:
        counter += combinations_count(value,2)
print(counter)


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 = [input() for _ in range(n)]


def is_anagram(s_i, s_j):
    for k in range(10):
        found = False
        for l in range(10):
            if s_i[k] == s_j[l]:
                found = True
                break
        if not found:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if i == j:
            continue
        if is_anagram(s[i], s[j]):
            num += 1
            records[i].append(j)
print(num)


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

num = 0
num_same = 0
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += num_same * (num_same - 1) / 2
        num_same = 1
        break
    num_same += 1
print(num)


n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()


def num_cmb(a, b):
    enum = 1
    denom = 1
    for i in range(b):
        enum *= (a - i)
        denom *= (b - i)
    return enum // denom


sum = 0
count = 1
prev = s[0]
for s_i in s[1::]:
    if prev == s_i:
        count += 1
    else:
        sum += num_cmb(count, 2)
        count = 1
        prev = s_i
if 0 < count:
    sum += num_cmb(count, 2)
print(sum)


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):
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

list = [[0 for i in range(26)] for j in range(n)]
#list[0][1]=1
#print(list)

hash=[]
for i in range(0,26):
	hash.append([])

for i in range(0,n):
	tmp=input()
	hoge=0
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1
		hoge+=ord(tmp[j])-ord("a")
	hoge=hoge%26
	hash[hoge].append(i)
#print(hash)

sum=0

for i in range(0,26):
	for j in range(0,len(hash[i])-1):
		for k in range(j,len(hash[i])):
			#print(i)
			#print(hash[i][j])
			#print(hash[i][k])
			for m in range(0,26):
				if(list[hash[i][j]][m]!=list[hash[i][k]][m]):
					break
				elif(m==25):
					sum+=1



#	for j in range(i+1,n):
#		for k in range(0,26):
#			if(list[i][k]!=list[j][k]):
#				break
#			elif(k==25):
#				sum+=1

print(sum)

#print(list)
#print(list[0][:])



# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
fuga = [0 for i in range(10)]

wordlist={}
for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		fuga[j]=tmp[j]
	fuga.sort()
	hoge=fuga[0]+fuga[1]+fuga[2]+fuga[3]+fuga[4]+fuga[5]+fuga[6]+fuga[7]+fuga[8]+fuga[9]

	if(hoge in wordlist):
		wordlist[hoge]+=1
	else:
		wordlist[hoge]=1

#print(hoge)
#print(wordlist)

total=0
for i in wordlist:
	t=wordlist[i]
	if(t>=2):
		total+=t*(t-1)//2


print(total)

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())
d = {}
for _ in range(n):
  s = input()
  k = set(list(s))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) / 2
print(ans)

n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = tuple(sorted(list(s)))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 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):
iport numpy as np
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append(np.zeros(10))
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.sort()
a=0
for i in range(n-1):
    for j in range(n-1-i):
        if ans[i]==ans[i+j+1]:
            a+=1
        else:
            break

print(int(a))


import numpy as np
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append(np.zeros(10))
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.sort()
a=0
for i in range(n-1):
    for j in range(n-1-i):
        if ans[i]==ans[i+j+1]:
            a+=1
        else:
            break

print(int(a))


n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

lis=[]
for i in range(n):
    lis.append(ans[i][0])
    for j in range(9):
        lis[i]+=ans[i][j+1]

a=0
#print(lis)

dic={lis[0]:1}
for i in range(n-1):
    if lis[i+1] in dic.keys():
        a+=dic[lis[i+1]]
        dic[lis[i+1]]+=1
    else:
        dic[lis[i+1]]=1

print(int(a))


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):
N = int(input())
s = sorted([sorted((input())) for i in range(N)])
count = 0

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

N = int(input())
s = sorted([sorted((input())) for i in range(N)])
count = 0

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

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

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

N = int(input())
s = [sorted((input())) for i in range(N)]
count = 0

for i in range(N-1):
     if(s[i]==s[i+1]):     
        count += 1
        
print(count)

N = int(input())
s = sorted([sorted((input())) for i in range(N)])
count = 0

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

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

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

N = int(input())
s = sorted([sorted((input())) for i in range(N)])
count = 0

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: 
            continue
        else:
            ana1 = []
            ana2 = []
            for k in range(10):
                ana1.append(S[i][k])
                ana2.append(S[j][k])
                ana1.sort()
                ana2.sort()
            print(ana1,ana2)
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: 
            continue
        else:
            ana1 = [S[i]]
            ana2 = [S[j]]
            ana1.sort()
            ana2.sort()
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i == j or i > j: 
            continue
        else:
            ana1 = list(S[i])
            ana2 = list(S[j])
            ana1.sort()
            ana2.sort()
            print(ana1,ana2)
            if ana1 == ana2:
                count += 1
            else:
                continue
print(count)

import collections


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

c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)




Verdicts: Wrong Answer

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())
s = []
for i in range(n):
  s.append(''.join(sorted(list(input().strip()))))
ans = 0
tmp = 0
ss = sorted(s)
prev = ''
for iss in ss:
  if prev != iss:
    prev = iss
    ans += int((tmp*(tmp+1))/2)
    tmp = 0
  elif prev == iss:
    print("prev :{}, iss :{}".format(prev, iss))
    tmp += 1
if tmp != 0:
  ans += int((tmp*(tmp+1))/2)
print(ans)


n = int(input())
s = []
for i in range(n):
  s.append(''.join(sorted(list(input().strip()))))
ans = 0
tmp = 0
ss = sorted(s)
prev = ''
for iss in ss:
  if prev != iss:
    prev = iss
    ans += int((tmp*(tmp+1))/2)
    tmp = 0
  elif prev == iss:
    # print("prev :{}, iss :{}".format(prev, iss))
    tmp += 1
if tmp != 0:
  ans += int((tmp*(tmp+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):
n = int(input())
s = []
ans = 0

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

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

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

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

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

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

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

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

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())
s = [input() for _ in range(N)]

ss = []
cnt = 0
for i in range(N):
    x = "".join(list(s[i]))
    if x in ss:
        cnt += ss.count(x)
    ss.append(x)

print(cnt)

from collections import Counter

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

ctr = Counter()
ans = 0
for si in S:
    x = "".join(sorted(list(si)))
    if x in ctr:
        ans += ctr[si]
    ctr[si] += 1

print(ans)

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

ss = []
for i in range(N):
    x = list(s[i])
    x.sort
    y = "".join(x)
    ss.append(y)

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if ss[i] == ss[j]:
            cnt += 1

print(cnt)

from collections import Counter

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

ctr = Counter()
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x in ctr:
        ans += ctr[Si]
    ctr[Si] += 1

print(ans)

from collections import Counter

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

ctr = Counter()
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x in ctr:
        ans += ctr[Si]
    ctr[Si] += 1

print(ans)

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

cnt = {}
ans = 0

for Si in S:
    x = "".join(sorted(list(Si)))
    if x not in cnt:
        cnt[x] = 0
    ans += cnt[x]
    cnt[x] += 1

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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 math
n = int(input())
l = [input() for _ in range(n)]
l = [sorted([j for j in i]) for i in l]
l = ["".join(i) for i in l]
al = list(set(l))
ans_dict = {}
ans = 0
for i in l:
    if i in ans_dict:
        ans += ans_dict[i]
        ans_dict[i]+=1
    else:
        ans_dict[i] = 1
    ans = 0

print(ans)

n = int(input())
l = [input() for _ in range(n)]
l = [sorted([j for j in i]) for i in l]
l = ["".join(i) for i in l]
al = list(set(l))
ans_dict = {}
ans = 0
for i in l:
    if i in ans_dict:
        
        ans += ans_dict[i]
        ans_dict[i]+=1
    else:
        ans_dict[i] = 1

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 *
 
n = int(input())
dic = defaultdict(int)
for i in range(n):
  dic["".join(sorted(input()))] += 1
print(dic.items())
 
ans = 0
for k,v in dic.items(): 
  print(v)
  ans += int(v*(v-1)/2)
  
print(ans)

from collections import *
 
n = int(input())
dic = defaultdict(int)
for i in range(n):
  dic["".join(sorted(input()))] += 1
print(dic.items())
 
ans = 0
for k,v in dic.items(): 
  print(v)
  ans += (v-1)
  
print(ans)

from collections import *
 
n = int(input())
dic = defaultdict(int)
for i in range(n):
  dic["".join(sorted(input()))] += 1
 
ans = 0
for k,v in dic.items(): 
  ans += int(v*(v-1)/2)
  
print(ans)

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())
l = [list(input()) for i in range(n)]
l = ["".join(sorted(i)) for i in l]
l.sort()
m = [l.count(l[i]) - 1 for i in range(n)]
o = [i*(i-1)/2 for i in m]
print(sum(o))


import collections
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
l = collections.Counter(s)
ans = sum(i*(i-1)//2 for i in l.values())
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):
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()

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()

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

n = k()
dict_a = {}

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

print(dict_a)
print(cnt)

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

n = k()
dict_a = {}

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

print(cnt)


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 = [''.join(sorted(list(input()))) for _ in range(N)]

from collections import Counter
a=Counter(S)

ans = 0

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

print(ans)

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

from collections import Counter
a=Counter(S)

ans = 0

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

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):
n = int(input())
sl = []
for i in range(n):
  S = ''.join(sorted(input()))
  sl.append(S)
print(sl)
count = 0
dict ={}

for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

n,*sl, = map(lambda x:''.join(sorted(x)),open(0).read().split())
count = 0
dict ={}

for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
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):
N = int(input())

strings = {}

for _ in range(N):
    s = sorted(list(input()))
    join_s = ''.join(s)
    if join_s in strings:
        strings[join_s] += 1
    else:
        strings[join_s] = 0
        
print(strings)

N = int(input())

strings = {}

ans = 0

for _ in range(N):
    s = sorted(list(input()))
    join_s = ''.join(s)
    if join_s in strings:
        strings[join_s] += 1
        ans += strings[join_s]
    else:
        strings[join_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):
n = int(input())
ans = 0

l = [sorted(input()) for _ in range(n)]
dellist = lambda items, indices: [item for idx, item in enumerate(items) if idx not in indices]

while True:
    a = l.pop(0)
    li = []
    for i in range(len(l)):
        if l[i] == a:
            li.append(i)

    dellist(l, li)

    ans += sum(range(li + 1))

print(ans)

from collections import Counter

n = int(input())
ans = 0

l = ["".join(sorted(input())) for _ in range(n)]

a = Counter(l).values()

for i in a:
    ans += sum(range(i))

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):
n = int(input())

a = [input() for i in range(n)]

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

a = sorted(a)

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

ans += (sum*(sum-1))/2
print(ans)

n = int(input())

a = [input() for i in range(n)]

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

a = sorted(a)

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

ans += (sum*(sum-1))/2
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):
import sys
input = sys.stdin.readline

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(dic)

import sys
input = sys.stdin.readline

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

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 = [sorted(input()) for _ in range(N)]
c = 0
for i in range(N-1):
  for j in range(i+1, N):
    if s[i]==s[j]:
      print((i,j), s)  
      c += 1
print(c)

N = int(input())
o = {}
c = 0
for _ in range(N):
    k = "".join(sorted(input()))
    if k not in o:
        o[k] = 0
    else:
        o[k] += 1
        c += o[k]
print(c)

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 Counter
N = int(input())
c = Counter([sorted(input()) for _ in range(N)])
print(sum([(v*(v+1))//2 for v in c.values()]))

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

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 collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.items():
  if v != 1:
    ctr += v
print(ctr)

import collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.values():
  if v != 1:
    for n in range(1,v):
      ctr+=n
      
print(ctr)

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):
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
from collections import defaultdict
n = I1()
d = defaultdict(int)
for i in range(n):
    d[sorted(input())]+=1
res=0
for i in d.keys():
    if d[i] > 1:
        yy=d[i]-1
        res+=yy*(yy+1)//2
print(res)


I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
from collections import defaultdict
n = I1()
d = defaultdict(int)
for i in range(n):
    d["".join(sorted(input()))]+=1
res=0
for i in d.keys():
    if d[i] > 1:
        yy=d[i]-1
        res+=yy*(yy+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):
def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = sorted(input())
        if word not in word_dict:
            word_dict[word] = 1
        else:
            count += 1

    print(count)
    
if __name__ == '__main__':
    C()


def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = ''.join(sorted(input()))
        if word not in word_dict.keys():
            word_dict[word] = 1
        else:
            count += word_dict[word]
            word_dict[word] += 1

    print(count)

if __name__ == '__main__':
    C()


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 collections
ans=0
N = int(input())
A=[]
for i In range(N):
    x=collections.Counter(list(input()))
    for s in A:
        if x==s:
            ans+=1
        else:
            A.append(x)
print(ans)

N = int(input())
dic = {}
ans = 0
for i in range(N):
    tmp = "".join(sorted(input()))
    if tmp in dic:
        ans += dic[tmp]
        dic[tmp] += 1
    else:
        dic[tmp] = 1
print(ans)




Verdicts: Runtime Error

Accepted