TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=0
for i in range(n):
  for j in range(i,n):
    if data[i]==data[j]:
      count=count+1
print(count)

n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  print(i)
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(decount)


n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  print(i)
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(int(decount))


n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(int(decount))

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=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
while len(s)>1:
  k=s.count(s[0])
  if k==1:
    continue
  else:
    cnt+=int(k*(k-1)/2)
  del s[:k]
print(cnt)

def resolve():
    n=int(input())
    s={}
    for i in range(n):
        x=str(sorted(list(input())))
        if x in s.keys():
            s[x]+=1
        else:
            s[x]=1
    ans=0
    if s:
        for i in s.values():
            ans+=i*(i-1)//2
    print(ans)

if __name__ == '__main__':
    resolve()

Verdicts: Time Limit Exceeded

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
N = int(input())
S = [''.join(sorted(input().rstrip())) for _ in range(N)]

print(S)
from collections import Counter

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


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


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


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())
C = []
for i in range(N):
    C.append("".join(sorted(input(i))))
B = set(C)
ans = 0
for j in B:
    t = C.count(j)
    if t > 1:
        ans += int(t*(t-1)/2 )
# 1->0, 2->1, 3->3, 4->6, 5->10 :: nC2
    
print(ans)

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


for i in range(len(s)):
    s[i].sort()
   
ans = 0 
cnt = 1
for i in range(1,N):
    for j in range(10):
        
        
        if(s[i][j] != s[i-1][j]):
            break
    else:
        cnt +=1
        continue
    ans += cnt*(cnt-1)//2
    cnt =1
ans +=cnt*(cnt-1)//2
print(ans)

import sys
import collections
from functools import reduce
import operator as op


def nCr(n,r):
    r = min(r,n-r)
    
    
    up = reduce(op.mul,range(n,n-r,-1),1)
    down= reduce(op.mul,range(r,0,-1),1)
    return up // down

def main():
    n = int(sys.stdin.readline().rstrip())
    
    sorted_letters =[''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]

    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >=2:
            count +=nCr(c,2)
        
    
    print(count)
    
if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
from collections import Counter
n=int(inout())
l=[''.join(sorted(input())) for _ in range(n)]
ans=0
for i in Counter(l).value():
  ans+=i*(i-1)//2
print(ans)

import itertools
import collections
n=int(input())
l=[input() for i in range(n)]
ans=0
for k in itertools.combinations(l,2):
  l1=[]
  l2=[]
  for t1 in k[0]:
    l1.append(t1)
  for t2 in k[1]:
    l2.append(t2)
  c1=collections.Counter(l1)
  c2=collections.Counter(l2)
  if c1.most_common()==c2.most_common():
    ans+=1
print(ans)


import itertools
import collections
n=int(input())
l=[input() for i in range(n)]
ans=0
for k in itertools.combinations:
  c1=collections.Counter(k[0])
  c2=collections.Counter(k[1])
  if c1.most_common()==c2.most_common():
    ans+=1
print(ans)

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

Verdicts: Runtime Error

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())
ana = {}
answer = 0

for i in range(N):
    s = sorted(input())
    new_str = ''.join(s)
    flag = 0

    try:
        k = ana.keys().index(new_str)y
        ana[k] += 1
        answer += ana[k]

    except:
        ana[new_str] = 0

print(answer)

N = int(input())
ana = {}
answer = 0

for i in range(N):
    s = sorted(input())
    new_str = ''.join(s)
    flag = 0

    if new_str in ana.keys():
        ana[new_str] += 1
        answer += ana[new_str]
        flag = 1

    if flag == 0:
        ana[new_str] = 0

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

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

N=int(input())
S_list=[]
for i in range(N):
    s=input()
    ss=list(s)
    ss.sort()
    S_list.append(ss)
S_list.sort()
ans=0
cnt=0
for i in range(1,N):
    if S_list[i]==S_list[i-1]:
        cnt+=1
        ans+=cnt
    else:
        cnt=0
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 = []
for i in range(n):
  s.append(input())

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

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

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

ans = 0
count = 1
s_pre = s[0]

for i in range(1, n):
    if s_pre == s[i]:
        count += 1
    else:
        ans += int(count * (count - 1) / 2)
        s_pre = s[i]
        count = 1

ans += int(count * (count - 1) / 2)
print(int(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())
L = [list(map(str, input().split())) for i in range(N)]

from collections import Counter
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.replace(' ', ''))
    if get_counter(first_word) == get_counter(second_word):
        return True
    else:
        return False

cnt=0
for i in range(N):
    for k in range(N):
        if k+1>len(L):
            continue
        if verify_anagrams(L[i],L[k+1]):
            cnt+=1

print(num)


N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for s in A:
    if s in D:
        count+=1
    else:
        D+=s
print(count)

N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(sorted(input()))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(str(sorted(input())))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

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(input())
s = [str(input()) for _ in range(n)]
t = []
ans = 0
for i in range(n):
    s[i] = sorted(s[i])

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


print(ans)


n = int(input())
s = [str(input()) for _ in range(n)]
ans = 0
for i in range(n):
    s[i] = "".join(sorted(s[i]))
    print(s[i])


for i in range(n):
    for j in range(i,):
        if s[i] == s[j]:
            ans += 1

print(ans)


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

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


print(ans)


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

t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
n=int(input())
s=[None]*n
for i in range(n):
  s[i]=sorted(input())
import collections
c=collections.Counter(s)
ans=0
for v in c.valeus():
  ans+=(v*(v-1))//2
print(ans)
  

n=int(input())
s=[None]*n
for i in range(n):
  s[i]="".join(sorted(input()))
import collections
c=collections.Counter(s)
ans=0
for v in c.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 sys
import bisect
input = sys.stdin.readline
 
def main():
    n=int(input())
    s=[input() for i in range(n)]
    count=0
    
    for i in range(n):
        s[i]=sorted(s[i])
        
    for i in range(n-1):
        s[i].pop(0)
        
    for i in range(n-1):
        for j in range(n-i-1):
            if(s[i]==s[i+j+1]):
                count+=1
    
    print(count)
    
main()

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

Verdicts: Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
a = int(input())
t = [input() for i in range(a)]
cnt = 0
dict = {}
for i in range(a):
    src = "".join(sorted(t[i]))
    if src in dict.keys():
        dict[src] += 1
    else:
        dict[src] = 0
ans = 0
for a in dict.values():
    ans += a*(a+1)/2
print(ans)

a = int(input())
t = [input() for i in range(a)]
cnt = 0
dict = {}
for i in range(a):
    src = "".join(sorted(t[i]))
    if src in dict.keys():
        dict[src] += 1
    else:
        dict[src] = 0
ans = 0
for a in dict.values():
    ans += a*(a+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):
def main():
    n = int(input())

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

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

    print(count)


if __name__ == "__main__":
    main()


def main():
    n = int(input())

    count = 0
    found = {}
    for _ in range(n):
        strs = list(input())
        strs.sort()
        str = ''.join(strs)
        if str in found:
            count += found[str]
            found[str] += 1
        else:
            found[str] = 1

    print(count)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
N=int(input())
ls=[]
n=0
for i in range(N):
    str1=''.join(sorted(input()))
    ls.count(str1)
    ls.append(str1)
print(n)        


N=int(input())
dic={}
ans=0
for i in range(N):
    str1=''.join(sorted(input()))
    n=len(str1)
    if n in dic:
        if str1 in dic[n]:
            ans+=dic[n][str1]
            dic[n][str1]+=1
        else:
            dic[n][str1]=1
    else:
        dic[n]={str1: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())
d=dict()
for i in range(n):
    s="".join(sorted(input()))
    if s in d:
        d[s]+=1
    else:
        d[s]=1
print(d)
ans=0
for k in d.values():
    ans+=k*(k-1)//2
print(ans)

n=int(input())
d=dict()
for i in range(n):
    s="".join(sorted(input()))
    if s in d:
        d[s]+=1
    else:
        d[s]=1
ans=0
for k in d.values():
    ans+=k*(k-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):
#input
N = int(input())
S = [sorted(input()) for i in range(N)]

ana = 0
for s1 in S:
    for s2 in S:
        if s1 == s2:
            ana += 1

print((ana - N) / 2)

import collections

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

S = collections.Counter(S)

ans = 0
for k, v in S.items():
    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):
import math

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


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


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

print(count)

n = int(input())
D = {}
count = 0
for i in range(n):
    line = "".join(sorted(list(input())))
    if line not in D:
        D[line] = 0
    else:
        D[line] += 1
        count += D[line]

print(count)


Verdicts: Runtime Error

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
from operator import itemgetter

n = int(input())
s = [sorted(input()) for _ in range(n)]
s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

print(s_sort)

for i in range(1, n):
    if l == s_sort[i]:
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

print(count)

from operator import itemgetter

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


s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

for i in range(1, n):
    if l == s_sort[i]:
        
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

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

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = 0
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))

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

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = []
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))


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

n = int(input())
d = {}
ans = 0
for st in range(n):
    s = ''.join(sorted(input()))
    if d.get(s) == None:
        d[s] = 1
    else:
        ans += d[s]
        d[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())
A={}
ans=0
for i in range(N):
    s=input()
    s=sorted(s)
    if A.get(s,"Not")=="Not":
        A[s]=1
    else:
        ans+=A[s]
        A[s]+=1
print(ans)

N=int(input())
P=[]
for i in range(N):
    s=input()
    s=sorted(s)
    P.append(s)

P=sorted(P)
last=P[0]
cnt=0
ans=0
for i in range(1,N):
    if P[i]==last:
        cnt+=1
        ans+=cnt
    else:
        last=P[i]
        cnt=0
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 numpy as np

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

for nn in range(n):
    sraw.append(sorted(input().encode()))

ans = 0

s = np.sort(np.array(sraw), axis=0).tolist()
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)


n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
from operator import mul
from functools import reduce
def cmb(n,r):
    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

N = int(input())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) for v in str_dict.values()]))

from operator import mul
from functools import reduce
def cmb(n,r):
    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

N = int(input())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) for v in str_dict.values() if v >= 2 else 0]))

from operator import mul
from functools import reduce
def cmb(n,r):
    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

N = int(input())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) if v>= 2 else 0 for v in str_dict.values()]))

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 numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = int(0)

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()
print(collections.Counter(moji))

for index in collections.Counter(moji).values():
  n = index - 1
  count += n*(1+n)/2

print(count)

import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = int(0)

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()
print(sum(collections.Counter(moji).values()))

import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = int(0)

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()

for index in collections.Counter(moji).values():
  n = index - 1
  count += n*(1+n)/2

print(count)

import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = int(0)

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()
print(sum(collections.Counter(moji).values())-1)

import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = 0

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()

for index in collections.Counter(moji).values():
  n = index - 1
  count += n*(1+n)/2

print(int(count))

Verdicts: 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 = []
for i in range(N):
    s = str(input())
    s = ''.join(sorted(s))
    S.append(s)

count = 0
for i in range(N):
    Si = S[i]
    for k in range(N):
        if i==k:
            None
        else:
            Sk = S[k]
            if Sk == Si:
                count += 1

print(count / 2)

"""
N = int(input())
dic = {}
ans = 0

for i in range(N):
    s = ''.join(sorted(input()))
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)
"""


N = int(input())
S = []
for i in range(N):
    s = str(input())
    s = ''.join(sorted(a))
    S.append(s)

count = 0
for i in range(N):
    Si = S[i]
    for k in range(N):
        if i==k:
            None
        Sk = S[k]
        if Sk == Si:
            count += 1

print(count / 2)




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

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


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    t = list(r)
    t.sort()
    s[i] = ''.join(t)
d = {}
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 0
count = 0
for k, v in d.items():
    print(k, v)
    count += int((v + 1) * v / 2)
print(count)

import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    t = list(r)
    t.sort()
    s[i] = ''.join(t)
d = {}
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 0
count = 0
for k, v in d.items():
    count += int((v + 1) * v / 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):
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  print(sum([combinations_count(t, 2) for t in  c.values()]))
 
if __name__ == '__main__':
  main()

import sys 
from collections import Counter

def main():
  input = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += (t * (t-1)) // 2
  print(cnt)
 
if __name__ == '__main__':
  main()


Verdicts: Runtime Error

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
import collections
n = int(input())
a = []
res= 0
for i in range(n):
  tmp = collections.Counter(input()).most_common()
  if a.count(tmp) >= 1:
    res += a.count(tmp)
  a.append(tmp)
print(res)

n = int(input())
a = {}
for i in range(n):
  tmp = "".join(sorted(input()))
  if tmp in a:
    a[tmp] += 1
  else:
    a[tmp] = 1
res = [i*(i-1)//2 for i in a.values()]
print(sum(res))


Verdicts: Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Submission attempts (in order):
n = int(input())
s = ["" for _ in range(n)]

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

#print(s)

s_list = [[] for _ in range(n)]
for i in range(n):
    
    for j in range(10):
        s_list[i].append(s[i][j])
    
    s_list[i].sort()

check = []



for i in range(n):
    for j in range(i+1, n):
        c = (s_list[i] == s_list[j])
        if (c == True) and (i not in check) and (j not in check):
            check.append(i)
            check.append(j)

#print(check)
print(len(check))




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

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

dic = {}
for i in range(n):
    tmp = sorted(list(s[i]))
    tmp2 = "".join(tmp)
    if dic.get(tmp2) == None:
        dic[tmp2] = 1
    else:
        dic[tmp2] += 1

#print(dic)
ans = 0
for k, v in dic.items():
    #print(k, v)
    if v >= 2:
        num = (v-1)
        #print("num: ", num)
        #print("num//2*(num+1): ", num//2*(num+1))
        ans += num*(num+1)//2
        #print(ans)

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())
arr=[]
from collections import Counter
c=Counter([])
for _ in range n:
  s=input()
  z=[item for item in s]
  z.sort()
  z=tuple(z)
  c[z]+=1
ans=0
for item in c.values():
  ans+=(item*(item-1))//2
print (ans)

n=int(input())
arr=[]
from collections import Counter
c=Counter([])
for _ in range (n):
    s=input()
    z=[item for item in s]
    z.sort()
    z=tuple(z)
    c[z]+=1
ans=0
for item in c.values():
    ans+=(item*(item-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):
#from Collections import Counter

N = int(input())
count = 0
word = []
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

def str_sort(str):
    #f = lambda str: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return lambda str: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
for _ in range(N):
    word.append(str_sort(input()))


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

#from Collections import Counter

N = int(input())
count = 0
word = {}
def str_sort(str):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(str)
for _ in range(N):
    sorted_str = str_sort(input())
    if sorted_str not in word:
        word[sorted_str] = [0]
        word[sorted_str].append(1)
    else:
        if word[sorted_str] == 0:
            word[sorted_str][0] = 1
        else:
            word[sorted_str][0] += word[sorted_str][1]
            word[sorted_str][1] += 1
            
total = sum(
    v[0] for v in word.values()
)
print(word)
print(total)


a

#from Collections import Counter

N = int(input())
count = 0
word = {}
def str_sort(str):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(str)
for _ in range(N):
    sorted_str = str_sort(input())
    if sorted_str not in word:
        word[sorted_str] = 0
    else:
        if word[sorted_str] == 0:
            word[sorted_str] = 1
        else:
            word[sorted_str] += word[sorted_str] + 1
total = sum(
    v for v in word.values()
)
print(word)
print(total)


from collections import Counter
import math
def combination2(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

N = int(input())
l = []
for _ in range(N):
    tmp = input()
    tmp = sorted(tmp)
    l.append(''.join(tmp))

l = Counter(l)
ans = 0
for key, value in l.items():
    if value >= 2:
        ans += combination2(value)
print(ans)




Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: We will call a string obtained by arranging the characters contained in a string a in some order, an _anagram_ of a.  For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

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

#word_list=list(map(lambda x: ''.join(sorted(x)),S))
word_dict={}
for word in S:
  word=''.join(sorted(word))
  if word in word_dict.keys():
    word_dict[word] = word_dict[word]+(word_dict[word]+1)
  else:
    word_dict[word] = 0
print(word_dict)

word_dict={}
for word in S:
  word=''.join(sorted(word))
  if word in word_dict.keys() and word_dict[word]==0:#2nd
    word_dict[word] = word_dict[word]+1
  elif word in word_dict.keys() and word_dict[word]==1:#3rd
    word_dict[word]= word_dict[word]+2
  elif word in word_dict.keys() and word_dict[word]==3:#4th
    word_dict[word]= word_dict[word]+3
  elif word in word_dict.keys() and word_dict[word]==6:#5th
    word_dict[word]= word_dict[word]+4
  elif word in word_dict.keys() and word_dict[word]==10:#6th
    word_dict[word]= word_dict[word]+5
  elif word in word_dict.keys() and word_dict[word]==15:#7th
    word_dict[word]= word_dict[word]+6
  else:
    word_dict[word] = 0
print(word_dict)

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

list = {}
for i in S:
  i=''.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1

count = 0
for i in list.values():
  n = i - 1
  count = count + int(((n * (n + 1)) / 2))
  
print(count)

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

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

c = collections.Counter(list)
ans_list = c.most_common()
print([ans[1] for ans in ans_list if not ans[1]==1])

import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
ans = [ans[1] for ans in ans_list if not ans[1]==1]
print(sum(ans))

import collections

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

c = collections.Counter(list)
ans_list = c.most_common()
ans = [ans[1]*(ans[1]-1)//2 for ans in ans_list if not ans[1]==1]
ans_len = len(ans)
if ans_len==0:
    print(0)
else:
    print(sum(ans))

Verdicts: Wrong Answer

Wrong Answer

Accepted