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 Counter
from operator import mul
from functools import reduce


def inpl():
    return list(map(int, input().split()))


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


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

d = {}
for s in S:
    tmp = list(s)
    tmp.sort()
    d[tuple(tmp)] = d.get(tuple(tmp), 0) + 1

print(d)
for k, v in d.items():
    ans += cmb(v, 2)

print(ans)


from collections import Counter
from operator import mul
from functools import reduce


def inpl():
    return list(map(int, input().split()))


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


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

d = {}
for s in S:
    tmp = list(s)
    tmp.sort()
    d[tuple(tmp)] = d.get(tuple(tmp), 0) + 1

# print(d)
for k, v in d.items():
    ans += cmb(v, 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()) 
t=[[0]*10]*N
y=[[0]*10]*N

for i in range(N):
  s=input()
  for j in range(10):
    t[i][j]=s[j]
  y[i]=sorted(t[i])
  
count=0

for i in range(0,N-1):
  for j in range(i+1,N):
    #print(i,t[i])
    #print(j,t[1])

    if y[i]==y[j]:
        count+=1
    else:
      break

print(count)

from collections import Counter

N=int(input())
s=[0]*N
t=[0]*N
d=dict()
cnt=0

for i in range(N):
  s[i]=input()
  t[i]=str(sorted(s[i]))
  if t[i] not in d:
    d[t[i]] =1
    #print(i,d)
  else:
    cnt += d[t[i]]
    d[t[i]] +=1
    #print(i,d)

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):
from math import factorial
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = int(factorial(aas) / factorial(2) / factorial(aas - 2 ))
        ans += abs
print(ans)

import sys
sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = cmb(aas,2)
        ans += int(abs)
print(ans)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = cmb(aas,2)
        ans += int(abs)
print(ans)

from collections import Counter

N = int(input())
s = Counter()
for i in range(N):
    s[''.join(sorted(input()))] += 1
ans = 0
for kw, count in s.most_common():
    for i in range(1, int(count)):
        ans += i
    if int(count) < 2:
        break
print(ans)

Verdicts: 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):
n=int(inpput())
list=[input() for i in range(n)]
lists=[]
for i in list:
  lists.append(''.join(sorted(i)))
  
print(len(lists)-len(set(lists)))

n = int(input())

words = {}
anagrams = 0

for i in range(n):
    word = "".join(sorted(input()))
    if word not in words:
        words[word] = 1
    else:
        anagrams += words[word]
        words[word] += 1

print(anagrams)


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())
str = [input().sort for i in range(N)]
dict = {}
count = 0

print(str)

N = int(input())
str = [''.join(sorted(input())) for i in range(N)]
dict = {}
sum = 0

for i in range(N):
  try:
    dict[str[i]] += 1
  except KeyError:
    dict[str[i]] = 1

for i in dict.values():
  sum += (i*(i-1))//2

print(sum)

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 = list(list(input())for i in range(N))
count = 1
ans = 0
s.sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        ans += count
        count += 1
    else:
        count = 1
print(ans)

N = int(input())
s = list(list(input())for i in range(N))
count = 1
ans = 0
for i in range(N):
    s[i].sort()
s.sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        ans += count
        count += 1
    else:
        count = 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):
N = int(input())
word = [input() for i in range(N)]
sorted_word = [sorted(list(word[i])) for i in range(N)]
dict_word = {sorted_word[i]:0 for i in range(N)}
count = 0
ans = 0

def sum_all(x):
  for i in range(x+1):
    y += i
  return y

for i in range(N):
  if sorted_word[i] in sorted_word[i+1:]:
	dict_word[sorted_word[i]] += 1
    
for value in dict_word.value():
  ans += sum_all(value)
  
print(ans)


N = input()
word = [input() for i in range(N)]
sorted_word = [word[i].sort() for i in range(N)]
count = 0
for i in range(N):
  for j in range(i, N):
    if sorted_word[i] == sorted_word[i+j]:
      count += 1
print(count)




N = int(input())
ans = 0
dict_word = {}
for i in range(N):
  sorted_word = [''.join(sorted(list(input()))) for i in range(N)]
  try:
    ans += dict_word[sorted_word]
    dict_word[sorted_word] += 1
  except:
    dict_word[sorted_word] = 1

print(ans)


import copy
N = int(input())
word = [input() for i in range(N)]
sorted_word = [sorted(list(word[i])) for i in range(N)]
copy_word = copy.copy(sorted_word)
count = 0
for i in range(N-1):
  copy_word.remove(sorted_word[i])
  if sorted_word[i] in copy_word
    count += 1
print(count)



N = int(input())
ans = 0
dict_word = {}
for i in range(N):
  sorted_word = str(''.join(sorted(list(input()))))
  try:
    ans += dict_word[sorted_word]
    dict_word[sorted_word] += 1
  except:
    dict_word[sorted_word] = 1
print(ans)

Verdicts: 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):
N = int(input())
S = []
for i in range(N):
    S.append(input())
d = {}
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        d[new_s] += d[new_s]
    else:
        d[new_s] = 1
print(max(d.values()))


N = [int(i) for i in input().split()]
S = []
d = {}
for i in range(N):
    S.append(input())
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        d[new_s] += d[new_s]
    else:
        d[new_s] = 1
print(max(d.values()))


N = int(input())
S = [input() for _ in range(N)]
d = {}
ans = 0
for s in S:
    ss = "".join(sorted(s))
    if ss in d:
        d[ss] += 1
        ans += d[ss]
    else:
        d[ss] = 0
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())
from collections import defaultdict
d=defaultdict(str)
for _ in range(n):
    s=list(input())
    s.sort()
    n=''.join(s)
    d[n]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)
    

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

print(ans)

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

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
import math
 
N = int(input())
words = [input() for i in range(N)] 
 
ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))
 
c = collections.Counter(L)
 
for i in c.values():    
    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)
 
print(int(ans))

import collections
from math import factorial

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

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += factorial(i) / factorial(2) / factorial(i - 2)

print(int(ans))


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

for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in dic.keys():
        dic[spell] += 1
    else:
        dic[spell] = 1

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)



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):
from collections import defaultdict
 
n = int(input())
S = [input() for _ in range(n)]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1
 
ans = 0
for v in d.values():
    print(v)
    ans += v*(v+1)//2
print(ans)

from collections import defaultdict
 
n = int(input())
S = [input() for _ in range(n)]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1
 
ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

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(list(input())) for i in range(n)]

#print(*count)

ans = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if count[i] == count[j]:
      ans += 1
print(ans)

n = (int)(input())
s = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 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):
k, x = tuple([int(i) for i in input().split(' ')])

print(" ".join([str(i) for i in range(x - k + 1, x + k)]))


n =  int(input())

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

d = {}

for e in s:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1

ans = 0
for k, v in d.items():
    ans += int(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):
n = int(input())
ls = [''.join(sorted(input())) for j in range(n)]
ls = sorted(ls)

s = ls[0]
i = 1
count = 1
ans = 0
while i < n:
  if ls[i] == s:
    count += 1
    i += 1
    if i == n-1:
      ans += count*(count-1)//2
  else:
    ans += count*(count-1)//2
    count = 1
    s = ls[i]
    i += 1
print(ans)


n = int(input())
ls = [''.join(sorted(input())) for j in range(n)]
ls = sorted(ls)

s = ls[0]
i = 1
count = 1
ans = 0
while i < n:
  if ls[i] == s:
    count += 1
    i += 1
    if i == n:
      ans += count*(count-1)//2
  else:
    ans += count*(count-1)//2
    count = 1
    s = ls[i]
    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):
n=int(input())
ans=0
for i in range(0,n):
  s=input().split()
  s[i]=''.join(sorted(s))
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)      


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

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


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


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


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


n=int(input())

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


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

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


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

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):
x = list(map(str, input().split())) 

n = int(x[0]) 
z = x[1:] 


def word_count(alphabet):
    res_dic = {}
    for i in alphabet:
        test = i in res_dic.keys() 
        if test == False: 
            res_dic[i] = 1
        elif test == True:
            plus = res_dic[i] + 1
            res_dic[i] = plus
    return res_dic


res = []
for i in z:
    alphabet = list(i)
    res.append(word_count(alphabet))


record = []
for i in res:
    for j in res:
        if i == j:
            record.append(1)
        elif i != j :
            record.append(0)

print(int((sum(record) - n)/2))

import collections

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

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

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 deque
sys.setrecursionlimit(20000000)


def main():
    n = int(input())
    s = [''.join(sorted(list(input()))) for _ in range(n)]

    ans = 0

    print(s)
    for a in range(len(s) - 1):
        for b in range(a + 1, len(s)):
            if s[a] == s[b]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


import sys
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    n = int(input())
    s = [''.join(sorted(list(input()))) for _ in range(n)]

    ans = 0

    print(s)
    for a in range(len(s) - 1):
        for b in range(a + 1, len(s)):
            if s[a] == s[b]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


import sys
from collections import deque
sys.setrecursionlimit(20000000)


def main():

    n = int(input())
    dic = {}
    for _ in range(n):
        t = ''.join(sorted(list(input())))
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 0

    def pattern(num):
        tmp = 0

        for i in range(1, num+1):
            tmp += i
        return tmp

    ans = 0
    for d in dic:
        if dic[d]:
            ans += pattern(dic[d])

    print(ans)


if __name__ == '__main__':
    main()



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 math

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

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

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




import math

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

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

print(answer)




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())
strList = []
for i in range(N):
  strList.append(input())

count = 0

dict = {}

for i in range(N):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  


count = 0;
for v in dict.values():
  count += (v * (v-1) / 2)
print(count)
 

N = int(input())
strList = []
for i in range(N):
  strList.append(input())

count = 0

dict = {}

for i in range(N):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  


count = 0;
for v in dict.values():
  count += (v * (v-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):
n=int(input())
s=[]
for i in range(n):
  s.append("".join(sorted(input())))
ss=set(s)
ans=0
for _ in ss:
  l=s.count(_)
  ans+=l*(l-1)/2
print(ans)


from collections import defaultdict
d=defaultdict(int)
n,*s=open(0).read().split()
for i in s:d["".join(sorted(list(i)))]+=1
print(sum(v*(v-1)//2 for v in d.values()))

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

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


d,a = {},0
for i in range(int(input())):
    k = ''.join(sorted(input()))
    d[k] = d.get(k,-1)+1
    a+= d[k]
print(a)

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 = ["".join(sorted(input())) for _ in range(N)]
print(A)
B = collections.Counter(s)
print(sum(i*(i-1)//2 for i in B.values()))

import collections
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
s.sort()
C = collections.Counter(s)
D = C.most_common()

ans = 0
for i in D:
    ans += i[1]*(i[1] - 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):
N = int(input())
s = [input() for i in range(N)]

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    cnt += factorial(v) / factorial(2) / factorial(v - 2)

print(cnt)

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

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1
# 
# for v in count_dict.values():
#     cnt += len(list(itertools.combinations(range(v), 2)))

print(cnt)

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


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

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    if v >= 2:
        # cnt += int(factorial(v)) / int(factorial(2)) / int(factorial(v - 2))
        cnt += cmb(v, 2)

print(cnt)

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_list=[]

for _ in range(N):
    s_list.append(input())
    
count=0
for i in range(N):
    for j in range(i+1,N):
        s1=[]
        s2=[]
        for k in range(10):
            s1.append(s_list[i][k])
            s2.append(s_list[j][k])
            
        print(sorted(s1),sorted(s2))
        if sorted(s1)==sorted(s2):
            count+=1
print(count)

N = int(input())
s_list=[]
s_dict={}
count=0

for i in range(N):
    s = "".join(sorted(input()))
    if s not in s_dict:
        s_dict[s]=0
    else:
        s_dict[s]+=1
        count+=s_dict[s]
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())
array = [sorted(input()) for x in range(n)]
set_array = set()
for i in array:
  set_array.add(i)
print(len(array) - len(set_array))


n = int(input())
array = [sorted(input()) for x in range(n)]
print(len(array) - len(set(array)))

n = int(input())
array = [sorted(input()) for x in range(n)]
print(len(set(array)) )


n = int(input())
array = [sorted(input()) for x in range(n)]
print(len(array) )


from collections import Counter

n = int(input())
array = sorted(["".join(sorted(input())) for x in range(n)])
counter = Counter(array)

res = 0
for key, value in counter.items():
    res += value*(value-1)//2
print(res)


Verdicts: Runtime Error

Runtime Error

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())
ans = 0
ls = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in ls:
        ans += ls[s]
        ls[s] += 1
    else:
        ls[s] = 1
print(ls)
print(ans)

n = int(input())
ans = 0
ls = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in ls:
        ans += ls[s]
        ls[s] += 1
    else:
        ls[s] = 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):
N = int(input())
words = dict()
count = 0
for i in range(N):
    s = ''.join(sorted(input()))
    if s in words:
        count += words[s]
        words[s] += 1
    else:
        words[s] = 1

N = int(input())
sc = [list(input()) for i in range(N)]
for i in sc:
    i.sort()
count = 0
for i in range(0 , len(sc)-1):
    for j in range(i+1,len(sc)):
        if sc[i] == sc[j]:
            count += 1

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

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().sort() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if s[i]==s[j]:
      cnt+=1
print(cnt)

n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in 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):
N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in D:
        D[S] += 1
    else:
        D[S] = 1
 
ans = 0
for i in D.values():
    out += i-1
print(out)

N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in D:
        D[S] += 1
    else:
        D[S] = 1
 
out = 0
for i in D.values():
    out += i * (i-1) //2
print(out)

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



def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    s = list(map(lambda s: ''.join(sorted(s)), s))
    hash = {}

    count = 0
    print(s[0])
    for i in range(0, n):
        if s[i] in hash:
            hash[s[i]] += 1
        else:
            hash[s[i]] = 1
        count += hash[s[i]] - 1
    return count


if __name__ == "__main__":
    main()


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



def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue
            if anagram(s[i], s[k]) == True:
                count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            b = b.replace(i, '')
            continue
        else:
            return False
    return True

# def anagram(a, b):
#     a = ''.join(sorted(a))
#     b = ''.join(sorted(b))
#     return a == b


if __name__ == "__main__":
    main()


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



def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            print('{}, {}'.format(i, k))
            if i == k:
                # print('continue: {}, {}'.format(i, k))
                continue

        # print('pass: {}, {}'.format(i, k))
        first = s[i]
        second = s[k]
        if anagram(first, second) == True:
            # print('anagram: {}, {}'.format(i, k))
            count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            a.replace(i, '')

        else:
            return False
    return True


if __name__ == "__main__":
    main()


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



def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    s = list(map(lambda s: ''.join(sorted(s)), s))
    hash = {}

    count = 0
    for i in range(0, n):
        if s[i] in hash:
            hash[s[i]] += 1
        else:
            hash[s[i]] = 1
        count += hash[s[i]] - 1
    return count


if __name__ == "__main__":
    main()


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 itertools

n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1    
    s_li.append(s_i)

ans = 0

for i in range(n):
    for j in range(n):
        if i >= j :
            continue
        if s_li[i] == s_li[j]:
            print(i, j)
            ans += 1
print(ans)

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

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_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):
n = int(input())
x =[]
ch = 1
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    x.append(s)
x.sort()
x.append('X')
for i in range(n):
    if x[i]==x[i+1]:
        ch+=1
    else:
        ans += ch*(ch-1)//2
        ch = 1
print(ans)
print(x)

n = int(input())
x =[]
ch = 1
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    x.append(s)
x.sort()
x.append('X')
for i in range(n):
    if x[i]==x[i+1]:
        ch+=1
    else:
        ans += ch*(ch-1)//2
        ch = 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):
n = int(input())
ls = []
l = [0 for i in range(n)]
for i in range(n):
  ls.append(input())
for i in range(n):
  for j in range(10):
    alpha = ord(ls[i][j]) - ord("a")
    l[i]+=10**alfa
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if l[i] == l[j]:
      ans+=1
print(ans)


n = int(input())
ls = []
dic = {}
ans = 0
for i in range(n):
    ls.append(input())
for i in range(n):
    tmp = "".join(sorted(ls[i]))
    if tmp in dic:
        ans += dic[tmp]
        dic[tmp] += 1
    else:
        dic[tmp] = 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):
N =int(input())
s = list(sorted(input()) for i in range(N))

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if s[i]==s[j]:
            cnt+=1
        else: break
print(cnt)

N =int(input())
s = list(sorted(input()) for i in range(N))
cnt = 0
for i in range(N):
    for j in range(N):
        if s[i]==s[j]:
            cnt+=1
print((cnt-N)/2)

import collections

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

Verdicts: Wrong Answer

Wrong Answer

Accepted