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

Submission attempts (in order):
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sort_tmp=sorted(tmp)
    stmp=''.join(sort_tmp)
    if((stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)

total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(s,total)


def myAnswer(N:int,S:list) -> int:
   counter = 0
   dic = {}
   for s in S:
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s] = 0
   for value in dic.values():
      counter += (value * (value + 1)) // 2
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = ["".join(sorted(list(input()))) for _ in range(N)]
   print(myAnswer(N,S))
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())
ans = 0
dict = {}
for _ in range(n):
    s = sorted(list(input()))
    if dict[s] == NULL:
        dict[s] = 0
    ans += dict[s]
    dict[s] += 1
print(ans)

n = int(input())
ans = 0
dict = {}
for _ in range(n):
    s = str(''.join(sorted(list(input()))))
    try:
        ans += dict[s]
        dict[s] += 1
    except:
        dict[s] = 1
print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
N = int(input())
s = [input().split() for i in range(N)]
count = 0

s = [sorted(str(i)) for i in s]
print(s)
for i in range(N):
    for j in range(i+1, N):
        if s[i] == s[j]:
            count += 1
print(count)


N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
s.sort()
count = 0
num = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        num += 1
    else:
        count += num * (num - 1) // 2
        num = 1
print(count + num * (num - 1) // 2)


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 = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

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

print(cnt//2)

n = int(input())
arr = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

for i in range(n):
  for j in range(i, n):
    if i != j and arr[i] == arr[j]:      
      cnt += 1

print(cnt//2)

n = int(input())
arr = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

for i in range(n):
  for j in range(i, n):
    if i != j and arr[i] == arr[j]:      
      cnt += 1

print(cnt//2)

import collections

from scipy.special import comb


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

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

cc = collections.Counter(aa)
c = [c[1] for c in cc.items() if c[1] >1]

ans = 0
for i in range(len(c)):
  ans += comb(c[i], 2, exact=True)
  

print(int(ans))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import collections

n = int(input())
a = []
ans = 0
for i in range(n):
    a.append("".join(sorted(input())))

c = collections.Counter(a)
an = c.values()

for i in an:
    ans += i*(i-1)/2
print(ans)

import collections

n = int(input())
a = []
ans = 0
for i in range(n):
    a.append("".join(sorted(input())))

c = collections.Counter(a)
an = c.values()

for i in an:
    ans += i*(i-1)/2
print(int(ans))

Verdicts: Wrong Answer

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

Submission attempts (in order):
from collections import Counter
 
def get_counter(s):
    return Counter(s)

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

ans = 0
i = 0
while i < len(l):
    ans += sum([get_counter(l[i]) == get_counter(l[n]) for n in range(i+1,n)])
    i += 1
print(ans)

import sys
sys.setrecursionlimit(10**6)

n = int(input())

d = {}

for i in range(n):
    t = input()
    t = ''.join(sorted(t))
    d[t] = d.get(t,0) + 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):
from collections import Counter

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


for i in range(N):
  s[i] = Counter(s[i]).most_common()
  

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

for i in range(N):
  s[i] = list(set(s[i]))
  
print(len(set(s)))

from collections import Counter

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


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



s = Counter(s).most_common()
ans = 0
for p in s:
  ans += p[1] * (p[1]-1) // 2
  
print(ans)

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
import math

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

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

cnt = 0

#         for j in range(1,n-i):
#                 if s_l[i] == s_l[i+j]:
#                         cnt += 1
set_s_l = set(s_l)
l = []
for val in set_s_l:
        l.append(s_l.count(val))
for i in l:
        cnt += c(i,2)
print(cnt)

import math

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

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

cnt = 0

# set_s_l = set(s_l)
# if len(s_l) == len(set_s_l):
#         print(0)
# else:
#         l = []
#         for val in set_s_l:
#                 l.append(s_l.count(val))



#                                 cnt += 1

#                                 cnt +=i
#                         else:
#                                 cnt += c(i,2)
#         print(cnt)
set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        for i in range(n):
                for j in range(1,n-i):
                        if s_l[i] == s_l[i+j]:
                                cnt += 1

import math
from collections import defaultdict

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s = list(input())
        s.sort()
        s_l.append(''.join(s))


#         s_l.append(''.join(sorted(s_i_l[i])))
#         # for x in sorted(s_l[i]):
#         #         a += x
#         # s_l[i] = a
cnt = 0

d = defaultdict(lambda: 0)
for s in s_l:
        d[s] += 1

for v in d.values():
        cnt += int(v*(v-1)/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):
from math import factorial
N=int(input())
count=[0]
u=0
s=[sorted(input()) for i in range(N)]
s=sorted(s)
for t in range(N-1):
    if s[t+1]==s[t]:
        count[u]+=1
    else:
        u.append(0)
for i in range(u):
    a=factorial(u)/factorial(2)/factorial(u-2)
print(a)

N=int(input())
count=0
s=[input() for i in range(N)]
n=['a' for t in range(N) for i in range(t+1,N) if s[t].sort==s[i].sort]
print(len(n))

from collections import Counter
N=int(input())
s=[0 for _ in range(N)]
count=0
for i in range(N):
    s[i]=input()
for t in range(N):
    for i in range(N):
        if Counter(s[i])==Counter(s[t]):
            count+=1
            print(s[i],s[t])
print(int((count-N)/2))

N=int(input())
S=[sorted((input())) for i in range(N)]
P={}
for i in range(N):
    if 'S[i]' in P:
        P['S[i]']+=1
    else:
        P['S[i]']=0
print(sum(P.values()))

from math import factorial
N=int(input())
count=[0]
u=0
s=[sorted(input()) for i in range(N)]
s=sorted(s)
for t in range(N-1):
    if s[t+1]==s[t]:
        count[u]+=1
    else:
        count.append()
for i in range(u):
    a=factorial(u)/factorial(2)/factorial(u-2)
print(a)

N=int(input())
S=[''.join(sorted((input()))) for i in range(N)]
P={}
for i in range(N):
    if S[i] in P:
        P[S[i]]+=1
    else:
        P[S[i]]=0
for i in P.keys():
    if P[i]>=2:
        P[i]=P[i]*(P[i]+1)/2
print(int(sum(P.values())))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

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 itertools

n = int(input())

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


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


if __name__ == '__main__':
    count = 0
    for k, g in itertools.groupby(sorted(in_str)):
        n = sum(1 for _ in g)
        if n == 0:
            continue
        count += cmb(n, 2)
    print(count)


import itertools

n = int(input())

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


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


if __name__ == '__main__':
    count = 0
    for k, g in itertools.groupby(sorted(in_str)):
        n = sum(1 for _ in g)
        if n == 1:
            continue
        count += cmb(n, 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):
#137c
# sys.stdin.readline()
import sys
input = sys.stdin.readline

N = int(input())
A = [str(input()) for _ in range(N-1)]
A = [str[0:10] for str in A]
A.append(str(input()))

sList = []
append = sList.append
ans = 0

for string in A: #2<N<10^5
 
    
    dictionarized_string = {letter: string.count(letter) for letter in string}
    ans += sList.count(dictionarized_string)
    append(dictionarized_string)
    
print(ans)

#137c
N = int(input())
s_dict = {}
ans = 0


for i in range(N): #2<N<10^5
  # https://www.lifewithpython.com/2015/05/python-count-characters-in-string.html
  string = list(input())
  string.sort(reverse=False)
  
  #print(tuple(string))
    
  if tuple(string) in s_dict:
    s_dict[tuple(string)] += 1
  else:
    s_dict[tuple(string)] = 1

for i in s_dict.values():
  if i != 1:
    ans += sum([i for i in range(1,i)])

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 = [str(input()) for i in range(n)]
s_sort = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        ans += s_sort[j:].count(s_sort[i])

print(ans)

n = int(input())
s = [str(input()) for i in range(n)]
s_sort = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        b = 0
        for k in range(10):
            if ss[i][k] != ss[j][k]:
                b = 1
                break
        if b == 0:
            ans += 1
                
print(ans)

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

ss = [''.join(sorted(i)) for i in s]
ans = 0
key_dict = {}

for i in ss:
    if i in key_dict:
        key_dict[i] += 1
    else:
        key_dict[i] = 1

a = key_dict.values()
al = [i * (i-1) / 2 if i > 1 else 0 for i in a]

ans = sum(al)
print(ans)

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

ss = [''.join(sorted(i)) for i in s]
ans = 0
key_dict = {}

for i in ss:
    if i in key_dict:
        key_dict[i] += 1
    else:
        key_dict[i] = 1

a = key_dict.values()
al = [i * (i-1) / 2 if i > 1 else 0 for i in a]

ans = int(sum(al))
print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
def moji(s):
    tmp = []
    for i in range(10):
        tmp.append(s[i])
    tmp.sort()
    new_s = ''
    for i in range(10):
        new_s += tmp[i]
    return new_s

N = int(input())
dic = {}
ans = 0
for i in range(N):
    tmp = moji(input())
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic.values():
    ans += C(i,2)
print(ans)

from collections import defaultdict
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    if n <= 1:
        return 0
    return P(n, r)//math.factorial(r)
N = int(input())
d = defaultdict(int)
for i in range(N):
    d[','.join(sorted(input()))] += 1
ans = 0
for value in d.values():
    ans += C(value,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=[]
for i in range(n):
    s.append(input())

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

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

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)]
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]], 2 )


print(count)

nn = int(input())
s=[]
for i in range(nn):
    s.append(input())

list_s = []
for j in range(nn):
    
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(nn):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

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)]
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]], 2 )


print(count)

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

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

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

def cmb(num):
    if num == 1:
        return 0
    elif num == 2:
        return 1
    else:
        return (num * (num-1) // 2)
  
count = 0
for k in m.keys():
        count += cmb( m[k] )


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):
# -*- coding: utf-8 -*-
n = int(input())
s = [0]*n
count = 0
each_count = {}

for si in s:
    tmp = list(str(input()))
    tmp.sort()
    si = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)


# -*- coding: utf-8 -*-
n = int(input())
s = [0]*n
count = 0
each_count = {}

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)


Verdicts: Wrong Answer

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

Submission attempts (in order):
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = [sorted(stdin.readline().rstrip()) for _ in range(n)]

gr = groupby(sary.sort())

res = 0

for k, g in gr:
    if k >= 2:
        res += k * (k - 1) // 2

print(res)

from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = sorted(["".join(sorted(stdin.readline().rstrip())) for _ in range(n)])

gr = groupby(sary)

res = 0

for k, g in gr:
    num = len(list(g))
    if  num >= 2:
        res += num * (num - 1) // 2

print(res)

Verdicts: Runtime Error

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

Submission attempts (in order):

x = []
n = int(input())
for i in range(n):
    x.append(sorted(list(input())))
x = sorted(x)
s = 0
su = 0

for i in range(0,n-1):
    if(x[i] == x[i+1]):
        s=s+1
        continue
    else:
        su += s*(s+1)/2
        s=0
su += s*(s+1)//2
print(su)

    


x = []
n = int(input())
for i in range(n):
    x.append(sorted(list(input())))
x = sorted(x)
s = 0
su = 0

for i in range(0,n-1):
    if(x[i] == x[i+1]):
        s=s+1
        continue
    else:
        su += s*(s+1)//2
        s=0
su += s*(s+1)//2
print(su)

    

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

List=[''.join(sorted(input())) for i in range(N)]
List.sort()
List.extend("1")
cnt = 0
num = 1

for i in range(N):
  a = List[i]
  b = List[i+1]
  if a != b:   
    cnt = cnt + num * (num-1) / 2
    num = 0 
  else:
    num = num + 1

print(int(cnt))

N = int(input())

List=[''.join(sorted(input())) for i in range(N)]
List.sort()
List.extend("1")
cnt = 0
num = 0

for i in range(N):
  a = List[i]
  b = List[i+1]
  if a != b:   
    cnt = cnt + num * (num+1) / 2
    num = 0 
  else:
    num = num + 1

print(int(cnt))

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
S = []
for _ in range(N):
    s = [0]*26
    for i in map(lambda: ord(c)-97, input()):
        s[i] += 1

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

print(res)

N = int(input())
d = dict()

for _ in range(N):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

print(int(sum(map(lambda x: (x+1)*x/2, d.values()))))

Verdicts: Runtime Error

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

Submission attempts (in order):
num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
new_strs.sort()
compact_strs = list(set(new_strs))

cnt = 0
for str in compact_strs:
    str_count = new_strs.count(str)
    print(f'str_count:{str_count}')
    if str_count >= 2:
        cnt += int(str_count*(str_count-1)/2)

print(cnt)


num = int(input())

strs = [[] for i in range(num)]
for i in range(num):
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
shorten_strs = list(set(new_strs))

cnt = 0

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

for str in shorten_strs:
    nums = new_strs.count(str)
    if nums > 2:
        cnt += comb_count(nums, 2)

print(cnt)


from collections import Counter

num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def sort(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: sort(v), strs))
strs_length = len(new_strs)

sum = 0
counter = Counter()
for tmp_str in new_strs:
    sum += counter[tmp_str]
    counter[tmp_str] += 1

print(sum)


Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
from collections import Counter


def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = sorted(input())

        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)


if __name__ == "__main__":
    main()


from collections import Counter


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


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

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

Submission attempts (in order):
N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
print(sorteds)
M=len(list(set(sorteds)))
print(N-M)

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

N=int(input())
strings=[sorted(input()) for a in range(N)]
strings.sort()
sums=0
sorteds=strings
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)



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

N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
sorteds.sort()
print(sorteds)
sums=0
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)



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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=_collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if tp[1]!=1:
        sums=sums+combinations_count(tp[1],2)
    else:break
    
print(sums)

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

Verdicts: Wrong Answer

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


sdict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        
        sdict[s_i]+= 1
        continue

    for j in range(i+1,N):
        sdict[s_i] = 0

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

print(ans)


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

#print(s)


sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 0

ans = 0
for i in sdict.values():
    ans += i*(i-1)//2
print(ans)


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

#print(s)


sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 1

ans = 0
for i in sdict.values():
    ans += i*(i-1)//2
print(ans)


Verdicts: Wrong Answer

Wrong Answer

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

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

su=[]
for i in s:
    su=sorted(list(i))
    i="".join(su)


count=0
while len(su)>0:
  j=su[0]
  del su[0]
  c=su.count(j)+1
  count+=c*(c-1)/2
  su=[i for i in su if i!=j]
  
print(int(count))

import collections
N=int(input())
su=["".join(sorted(list(input()))) for _ in range(N)]

C=list(collections.Counter(su).values())

ans=0
for i in C:
  if i>1:
    ans+=i*(i-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 = []
for i in range(n):
    a = input()
    a = set([i for i in a])
    s.append(a)
count = 0
for i in range(len(s)):
    for j in range(i+1,len(s)):
        if s[i]==s[j]:
            count+=1
        break
print(count)

import math
n = int(input())
s = []
for i in range(n):
    a = input()
    a = [i for i in a]
    a = sorted(a)
    s.append(a)
count = 0
s = sorted(s)
p = 0
try:
    for i in range(len(s)):
        if s[i]==s[i+1]:
            p+=1
        else:
            count+=sum(list(range(p+1)))
            p=0
except:
    count+=sum(list(range(p+1)))
print(count)

Verdicts: Wrong Answer

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

Submission attempts (in order):
import collections
from scipy.misc import comb
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
r = collections.Counter(s)
for k, v in r.items():
    if v > 1:
        c += comb(v, 2)

print(int(c))


from itertools import combinations
import collections
from scipy.misc import comb
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
r = collections.Counter(s)
for k, v in r.items():
    if v > 1:
        c += comb(v, 2)

print(c)


import collections

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

c = 0
r = collections.Counter(s)
for v in r.values():
    c += (v * (v - 1)) // 2

print(c)


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):
def main():
  from collections import Counter
  from sys import stdin
  readline = stdin.readline()
  N = int(readline())
  t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
  print(sum(t[k] * (t[k] - 1) // 2 for k in t))
main()


def main():
  from collections import Counter
  from sys import stdin
  readline = stdin.readline
  N = int(readline())
  t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
  print(sum(t[k] * (t[k] - 1) // 2 for k in t))
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):
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    print(a)
    if a in ctr:
        ans += ctr[a]
    ctr[a] += 1
print(answer)

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    print(a)
    if a in ctr:
        answer += ctr[a]
    ctr[a] += 1
print(answer)

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
ctr = Counter()
answer = 0
for s in S:
    a = ''.join(sorted(list(s)))
    #print(a)
    if a in ctr:
        answer += ctr[a]
    ctr[a] += 1
print(answer)

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):
from collections import Counter
n=int(input())
strings = []
for i in range(n):
    strings.append(input())
dic = {}
for l in [Counter(s) for s in strings]:
    ll = str(l)
    if ll in dic:
        dic[ll] += 1
    else:
        dic[ll] = 0
res = 0
for k , v in dic.items():
    res += v * (v + 1)/2
print(res)

from collections import Counter
n=input()
strings = []
for i in range(n):
    strings.append(input())
dic = {}
for l in [Counter(s) for s in strings]:
    ll = str(l)
    if ll in dic:
        dic[ll] += 1
    else:
        dic[ll] = 0
res = 0
for k , v in dic.items():
    res += v * (v + 1)/2
print(res)

from collections import Counter
n=int(input())
strings = []
for i in range(n):
    strings.append(input())
dic = {}
for string in strings:
    c = Counter(string)
    s = "".join([str(c[l]) for l in "abcdefghijklmnopqrstuvwxyz"])
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 0
res = 0
for k , v in dic.items():
    res += v * (v + 1)/2
print(int(res))

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):
from scipy.misc import comb
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += int(comb(cnt,2))
print(ans)

N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += cnt * (cnt-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):
def cmb(n, r):
    if n - r < 0: return 0
    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

# print(cmb(1,2))

N = int(input())
s = []

for i in range(N):
    temp = ''.join(sorted(input()))
    s.append(temp)

# s = sorted(s)

# print(s)
ans = 0
count = 1

for i in range(1,N):
    if s[i-1] == s[i]:
         count += 1
    else:
        if count >= 2:
            ans += cmb(count,2)
            count = 1

ans += cmb(count,2)

print(ans)


def cmb(n, r):
    if n - r < 0: return 0
    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

# print(cmb(1,2))

N = int(input())
s = []

for i in range(N):
    temp = ''.join(sorted(input()))
    s.append(temp)

s = sorted(s)

# print(s)
ans = 0
count = 1

for i in range(1,N):
    if s[i-1] == s[i]:
         count += 1
    else:
        if count >= 2:
            ans += cmb(count,2)
            count = 1

ans += cmb(count,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 = []
for _ in range(N):
    S.append(input())



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

S.sort()

res=0
for i in range(len(S)-1):
        if S[i] == S[i+1]:
                print(S[i])
                res+=1

print(res)

N = int(input())

S = []
for _ in range(N):
    tmp=sorted(input())
    S.append(tmp)

for i in range(len(S)):
    S[i]=''.join(S[i])

import collections
from math import factorial

res=0
dic = {}
for tmp in S:
    if tmp in dic.keys():
        res+=dic[tmp]
        dic[tmp]+=1
    else:
        dic[tmp]=1

print(int(res))

Verdicts: Wrong Answer

Accepted