Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from math import factorial

MOD = 10 ** 9 + 7


def factorize(n):
    facts = defaultdict(int)
    while n % 2 == 0:
        n //= 2
        facts[2] += 1
    m = 3
    while m * m <= n:
        while n % m == 0:
            facts[m] += 1
            n //= m
        m += 2
    if 1 < n:
        facts[n] += 1
    return facts


def nCr(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


N, M = map(int, input().split())
factors = factorize(M)
ans = 1
for p, e in factors.items():
    ans = ans * nCr(N - 1 + e, e) % MOD
print(ans)

Fixed submission:
from collections import defaultdict


def factorize(n):
    facts = defaultdict(int)
    while n % 2 == 0:
        n //= 2
        facts[2] += 1
    m = 3
    while m * m <= n:
        while n % m == 0:
            facts[m] += 1
            n //= m
        m += 2
    if 1 < n:
        facts[n] += 1
    return facts


MOD = 10 ** 9 + 7  # should be a prime number
MAX = 10 ** 5 + 100
FACTS = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    FACTS[i] = FACTS[i - 1] * i % MOD
FACTINVS = [1] * (MAX + 1)
INVS = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    q, r = divmod(MOD, i)
    INVS[i] = -INVS[r] * q % MOD
    FACTINVS[i] = FACTINVS[i - 1] * INVS[i] % MOD


def nCr(n, r):
    return FACTS[n] * FACTINVS[r] * FACTINVS[n - r]


N, M = map(int, input().split())
factors = factorize(M)
ans = 1
for p, e in factors.items():
    ans = ans * nCr(N - 1 + e, e) % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(w[i].startswith(w[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')

Fixed submission:
N = int(input())
words = []
for _ in range(N):
    words.append(input())
print('Yes' if all(words[i].startswith(words[i-1][-1]) for i in range(1, N)) and len(set(words)) == N else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

D, G = map(int, input().split())
PC = []
for _ in range(D):
    p, c = map(int, input().split())
    PC.append((p, c))

ans = sum(p for p, _ in PC)
for ids in permutations(range(D)):
    score = 0
    num = 0
    for i in ids:
        p, c = PC[i]
        if score + (i + 1) * 100 * p + c < G:
            score += (i + 1) * 100 * p + c
            num += p
        else:
            for j in range(p):
                score += (i + 1) * 100
                num += 1
                if G <= score:
                    ans = min(ans, num)
                    break
            else:
                score += c
                if G <= score:
                    ans = min(ans, num)
        if G <= score:
            break
print(ans)

Fixed submission:
from itertools import permutations

D, G = map(int, input().split())
PC = []
for _ in range(D):
    p, c = map(int, input().split())
    PC.append((p, c))

ans = sum(p for p, _ in PC)
for ids in permutations(range(D)):
    score = 0
    num = 0
    for i in ids:
        p, c = PC[i]
        if score + (i + 1) * 100 * p + c < G:
            score += (i + 1) * 100 * p + c
            num += p
        else:
            for j in range(p):
                score += (i + 1) * 100
                num += 1
                if G <= score:
                    ans = min(ans, num)
                    break
            else:
                score += c
                if G <= score:
                    ans = min(ans, num)
        if G <= score:
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
print len({map(int, raw_input().split())})

Fixed submission:
print len(set(map(int, raw_input().split())))
Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
N = len(s)


def judge(x):
    score = 0
    for a, b in zip(s, x):
        if (a, b) == ('p', 'g'):
            score -= 1
        elif (a, b) == ('g', 'p'):
            score += 1
    return score

if N % 2 == 0:
    x  = 'g' * (N / 2) + 'p' * (N / 2)
    score = judge(x)
else:
    score = 0
    for i in xrange(N / 2 + 1):
        x = 'g' * (N / 2) + 'p' * i + 'g' + 'p' * (N / 2 - i)
        score = max(score, judge(x))
print score

Fixed submission:
s = raw_input()
N = len(s)
print N / 2 - s.count('p')
Buggy python submission (verdict: Runtime Error):
xs = map(int, raw_input())
print 'YES' if sorted(xs) == [5, 5, 7] else 'NO'

Fixed submission:
xs = map(int, raw_input().split())
print 'YES' if sorted(xs) == [5, 5, 7] else 'NO'
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]


def dfs_numbering(i, M, V, ANS, cnt, v):
    V[i] = v
    for x in M[i]:
        if V[x] == -1:
            cnt = dfs_numbering(x, M, V, ANS, cnt, v)
    ANS[i] = cnt
    return cnt + 1

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        for i in range(n):
            if V[i] == -1:
                dfs_numbering(i, self.M, V, ANS, 0, 0)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

S = scc(n)
for i in range(m):
    S.add_edge(C[i][0], C[i][1])
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(*([len(ANS[i])] + ANS[i]))

Fixed submission:
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6 + 5)

def dfs_numbering(st, M, V, ANS, cnt, v):
    ST = [st]
    while len(ST) > 0:
        # print(ST,V)
        i = ST[-1]
        if ANS[i] == -1:
            V[i] = v
            end = 1
            for x in M[i]:
                if V[x] == -1:
                    ST.append(x)
                    end = 0
                    # cnt = dfs_numbering(x, M, V, ANS, cnt, v)
            if end == 1:
                ST.pop()
                ANS[i] = cnt
                cnt += 1
        else:
            ST.pop()
    return cnt

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        cnt = 0
        for i in range(n):
            if V[i] == -1:
                cnt = dfs_numbering(i, self.M, V, ANS, cnt, 0)

        # print(ANS)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        # print(ANS1)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

n, m = map(int,input().split())

S = scc(n)
for i in range(m):
    frm, to = map(int,input().split())
    S.add_edge(frm, to)
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(len(ANS[i]), end=" ")
    print(*ANS[i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

h, w, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]
CC = [[] for i in range(h)]
for i in range(m):
    CC[C[i][0]-1].append(C[i][1]-1)

for i in range(h):
    CC[i].sort()

A = [0] * h
B = [0] * w
for i in range(m):
    A[C[i][0]-1] += 1
    B[C[i][1]-1] += 1

# ans = 0
# for i in range(m):
#     ans = max(ans, A[C[i][0]-1] + B[C[i][1]-1] - 1)

D = [[A[i], i] for i in range(h)]
E = [[B[i], i] for i in range(w)]
D.sort(reverse=True)
E.sort(reverse=True)

# print(D,E)

from bisect import bisect
# if not ([D[0][1]+1, E[0][1]+1] in C):
#     # print("r1")
#     ans = D[0][0] + E[0][0]
# else:
ans = 0
aa = D[0][0] + E[0][0]
co = 0
F = []

for i in range(h):
    for j in range(w):
        if D[i][0] + E[j][0] == aa:
            F.append([D[i][1], E[j][1]])
            co += 1
        else:
            break
    # if co > m:
    #     break
# if co > m:
#     # print("r2")
#     ans = D[0][0] + E[0][0]
else:
    ha = 0
    # print(F)
    # print(CC)
    for i in range(len(F)):
        ind = bisect(CC[F[i][0]], F[i][1])
        if ind==0 or (ind >= 1 and CC[F[i][0]][ind-1] != F[i][1]):
            # print(CC[ind-1], F[i][1])
            ha = 1
            break
    if ha == 1:
        # print("r3")
        ans = D[0][0] + E[0][0]
    else:
        # print("m1")
        ans = D[0][0] + E[0][0] - 1
print(ans)



Fixed submission:
import sys
input = sys.stdin.readline

h, w, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]
CC = [[] for i in range(h)]
for i in range(m):
    CC[C[i][0]-1].append(C[i][1]-1)

for i in range(h):
    CC[i].sort()

A = [0] * h
B = [0] * w
for i in range(m):
    A[C[i][0]-1] += 1
    B[C[i][1]-1] += 1

# ans = 0
# for i in range(m):
#     ans = max(ans, A[C[i][0]-1] + B[C[i][1]-1] - 1)

D = [[A[i], i] for i in range(h)]
E = [[B[i], i] for i in range(w)]
D.sort(reverse=True)
E.sort(reverse=True)

# print(D,E)

from bisect import bisect
if not ([D[0][1]+1, E[0][1]+1] in C):
    # print("r1")
    ans = D[0][0] + E[0][0]
else:
    ans = 0
    aa = D[0][0] + E[0][0]
    co = 0
    F = []

    for i in range(h):
        for j in range(w):
            if D[i][0] + E[j][0] == aa:
                F.append([D[i][1], E[j][1]])
                co += 1
            else:
                break
        if co > m:
            break
    if co > m:
        # print("r2")
        ans = D[0][0] + E[0][0]
    else:
        ha = 0
        # print(F)
        # print(CC)
        for i in range(len(F)):
            ind = bisect(CC[F[i][0]], F[i][1])
            if ind==0 or (ind >= 1 and CC[F[i][0]][ind-1] != F[i][1]):
                # print(CC[ind-1], F[i][1])
                ha = 1
                break
        if ha == 1:
            # print("r3")
            ans = D[0][0] + E[0][0]
        else:
            # print("m1")
            ans = D[0][0] + E[0][0] - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q= map(int,input().split())
A = list(map(int,input().split()))
C = [list(map(int,input().split())) for i in range(q)]

for i in range(q):
    print(len(set(A[C[i][0]-1:C[i][1]])))

Fixed submission:
import sys
input = sys.stdin.readline
n,q= map(int,input().split())
A = list(map(int,input().split()))
C = [list(map(int,input().split())) + [i] for i in range(q)]
for i in range(q):
    C[i][0] -= 1
    C[i][1] -= 1
for i in range(n):
    A[i] -= 1

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

B = Bit(n+1)
ANS = [-1] * q
C.sort(key=lambda x:x[1])
G = [-1] * (max(A)+1)
ind = 0
for i in range(n):
    a = A[i]
    if G[a] != -1:
        # print("ADD", G[a]+1, -1)
        B.add(G[a]+1, -1)
    G[a] = i
    # print("ADD", G[a]+1, 1)
    B.add(G[a]+1, 1)
    while ind < q and C[ind][1] == i:
        # print("SUM", C[ind][1]+1, C[ind][0]+1-1)
        ANS[C[ind][2]] = B.sum(C[ind][1]+1) - B.sum(C[ind][0]+1-1)
        ind += 1

for i in range(q):
    print(ANS[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = input()

l = 2*10**5 + 5
A = [0] * l
for i in range(1,l):
    ab = format(i, "b")
    abo = ab.count("1")
    A[i] = i % abo

B = [-1] * l
B[0] = 0
# print(A[:10])

def dd(y):
    # print(y)
    if B[y] == -1:
        return dd(A[y])+1
    else:
        return B[y]

for i in range(1, l):
    # print(dd(i))
    B[i] = dd(i)

# print(B[:10000])

m = x.count("1")
m0 = m-1
m1 = m+1
M0 = [1]
M1 = [1]
for i in range(l):
    M0.append((M0[-1]*2) % m0)
    M1.append((M1[-1]*2) % m1)

n0 = 0
n1 = 0
for i in range(n):
    if x[n-1-i] == "1":
        n0 = (n0 + M0[i]) % m0
        n1 = (n1 + M1[i]) % m1

for i in range(n):
    nn = 0
    if x[i] == "1":
        nn = (n0 - M0[n-i-1]) % m0
    else:
        nn = (n1 + M1[n-i-1]) % m1
    print(B[nn]+1)



Fixed submission:
n = int(input())
x = input()

# n = 3
# x = "100"

l = 2*10**5 + 5
A = [0] * l
for i in range(1,l):
    ab = format(i, "b")
    abo = ab.count("1")
    A[i] = i % abo

B = [-1] * l
B[0] = 0
# print(A[:10])

def dd(y):
    # print(y)
    if B[y] == -1:
        return dd(A[y])+1
    else:
        return B[y]

for i in range(1, l):
    # print(dd(i))
    B[i] = dd(i)

# print(B[:100])

m = x.count("1")
m0 = m-1
m00 = m0
if m0 == 0:
    m0 = 1

m1 = m+1
M0 = [1]
M1 = [1]
for i in range(l):
    M0.append((M0[-1]*2) % m0)
    M1.append((M1[-1]*2) % m1)

n0 = 0
n1 = 0
for i in range(n):
    if x[n-1-i] == "1":
        n0 = (n0 + M0[i]) % m0
        n1 = (n1 + M1[i]) % m1

for i in range(n):
    nn = 0
    if x[i] == "1":
        nn = (n0 - M0[n-i-1]) % m0
    else:
        nn = (n1 + M1[n-i-1]) % m1
    print(B[nn]+1 if (m00!=0 or x[i]!="1") else 0)
Buggy python submission (verdict: Time Limit Exceeded):
# import sys
# input = sys.stdin.readline

n = int(input())

A = [1 for i in range(n+1)]

F = [0] * (n+1)

for i in range(2, n+1):
    
    
    if F[i] == 0:
        for j in range(i, n+1, i):
            F[j] = 1
        # L = [0] * (n+1)
        L = {}
        m = i
        while m <= n:
            # print("m",m)
            for j in range(m, n+1, m):
                try:
                    L[j] += 1
                except:
                    L[j] = 1
            m *= i
        # print(L)
        for j in L.keys():
            A[j] *= L[j]+1
# print(A)
# print(A[24])
ans = 0
for i in range(n+1):
    ans += i * A[i]

print(ans)

Fixed submission:
n = int(input())
ans = 0

for i in range(1, n+1):
    a1 = i
    d = i
    nn = n // i
    ans += (nn * (2*a1 + (nn-1)*d)) // 2
    # print(i,ans,a1,nn,d)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
A.sort()

ans = 1
for i in range(n):
    ans *= A[i]

if ans > 10**18:
    ans = -1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
A.sort()

ans = 1
for i in range(n):
    ans *= A[i]
    if ans > 10**18:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))

ans = 1
b = 0
L = [[0,0] for i in range(n)]
# L[-1][0] = A[-1]
# L[-1][1] = A[-1]
l = A[-1]
r = A[-1]
for i in range(n-1,-1,-1):

    L[i][0] = (l+1)//2 + A[i]
    L[i][1] = r + A[i]
    l = L[i][0]
    r = L[i][1]

if L[0][0] != 1:
    print(-1)
else:
    ans = 1
    now = 1
    for i in range(1, n):
        now = min(L[i][1], now*2)
        # print(i,now)
        ans += now
        now -= A[i]
    print(ans + A[-1])

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))

if n == 0:
    print(1 if A[0] == 1 else -1)
else:

    ans = 1
    b = 0
    L = [[0,0] for i in range(n)]
    # L[-1][0] = A[-1]
    # L[-1][1] = A[-1]
    l = A[-1]
    r = A[-1]
    for i in range(n-1,-1,-1):

        L[i][0] = (l+1)//2 + A[i]
        L[i][1] = r + A[i]
        l = L[i][0]
        r = L[i][1]

    if L[0][0] != 1:
        print(-1)
    else:
        ans = 1
        now = 1
        for i in range(1, n):
            now = min(L[i][1], now*2)
            # print(i,now)
            ans += now
            now -= A[i]
        print(ans + A[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
K = int(input())
 
lis = [i for i in range(1,K+1)]
a = 0
 
n = list(itertools.product(lis, repeat=3))
for i in range(len(n)):
    ma = math.gcd(math.gcd(n[i][0],n[i][1]),math.gcd(n[i][0],n[i][2]))
    a += ma
print(a)

Fixed submission:
from math import gcd
k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            ans += gcd(gcd(i, j), l)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
 
K = int(input())
 
lis = [i for i in range(1,K+1)]
a = []
 
for i in lis:
    for j in lis:
        for k in lis:
            a.append([i,j,k])
gcd_list = []
for i in a:
    e,f,g = map(int,i)
    e_f = math.gcd(e,f)
    e_g = math.gcd(e,g)
    e_f_g = math.gcd(e_f,e_g)
    gcd_list.append(e_f_g)
print(sum(gcd_list))

Fixed submission:
from math import gcd
k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            ans += gcd(gcd(i, j), l)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, p = map(int,input().split())
s = input()

mod = p
l = 100

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)


P = [0] * p

T = [1]
for i in range(n-1):
    T.append((T[-1] * 10) % p)

# a = 0
# for i in range(n):
#     a = (a * 10 + int(s[i]))
#     a = a%p
#     P[a] += 1

ans = 0
u = 0
v = 0
s = list(s)
for i in range(n):
    s[i] = int(s[i])
# for i in range(n):
#     print(u,P[(p-u)%p])
#     ans += P[(p-u)%p]
#     u = (u-int(s[n-1-i])) % p
#     u = u * inv(10%p, mod) % p
# print(s)
for i in range(n):
    v = (u * 10 + s[i]) % p
    P[v] += 1
    # qq = s[i-1] if i > 0 else 0
    ans += P[(p-v*s[i])%p]
    # print(ans)
    u = v
s -= 1
if s[-1] == 0:
    s += 1

print(ans)



Fixed submission:
n, p = map(int,input().split())
s = input()

mod = p
l = 100

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

T = [1]
for i in range(n-1):
    T.append((T[-1]*10) % p)

P = [0] * p
P[0] = 1

ans = 0
v = 0
S = [int(s[i]) for i in range(n-1,-1,-1)]

if p==2 or p==5:
    for i in range(n):
        ans += (int(s[i]) % p == 0) * (i+1)
else:
    for i in range(n):
        v = (v + T[i]*S[i]) % p
        ans += P[v]
        P[v] += 1
        # print(P)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

D = [float("inf")] * (h+10**4+3)
D[0] = 0
for j in range(n):
    for i in range(len(D)//A[j][0] + 1):
        D[i] = min(D[i],D[i-A[j][0]] + A[j][1])
    # print(D[:20])
# print(D[:20])
print(min(D[h:]))

# a = float("inf")
# for i in range(n):
#     for j in range(n):
#         for k in range(h//A[i][0]+1):
#             b = A[i][1] * k + A[j][1] * max(0,-((-h+k*A[i][0])//A[j][0]))
#             a = min(a,b)
#             print(A[i][1] , k , A[j][1] , max(0,-((-h+k*A[i][0])//A[j][0])))
#             print(i,j,k,a)
        
# print(a)

# for i in range(n):
#     A[i].append(A[i][0]/ A[i][1])
# A.sort(reverse=True)
# A.sort(key=lambda x:x[2], reverse=True)
# print(A)
# a = 0
# while h > 0:
#     i=0
#     k = h//A[i][0]
#     h -= k * A[i][0]
#     a += k * A[i][1]
#     print(h)
#     if h > 0:
#         for i in range(n):
#             A[i][0] = min(A[i][0], h)
#             A[i][2] = A[i][0] / A[i][1]
#         A.sort(reverse=True)
#         A.sort(key=lambda x:x[2], reverse=True)
#     print(A)
# print(a)


Fixed submission:
import sys
input = sys.stdin.readline
h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

D = [float("inf")] * (h+10**4+3)
D[0] = 0
for j in range(n):
    for i in range(len(D)):
        D[i] = min(D[i],D[i-A[j][0]] + A[j][1])
    # print(D[:20])
# print(D[:20])
print(min(D[h:]))

# a = float("inf")
# for i in range(n):
#     for j in range(n):
#         for k in range(h//A[i][0]+1):
#             b = A[i][1] * k + A[j][1] * max(0,-((-h+k*A[i][0])//A[j][0]))
#             a = min(a,b)
#             print(A[i][1] , k , A[j][1] , max(0,-((-h+k*A[i][0])//A[j][0])))
#             print(i,j,k,a)
        
# print(a)

# for i in range(n):
#     A[i].append(A[i][0]/ A[i][1])
# A.sort(reverse=True)
# A.sort(key=lambda x:x[2], reverse=True)
# print(A)
# a = 0
# while h > 0:
#     i=0
#     k = h//A[i][0]
#     h -= k * A[i][0]
#     a += k * A[i][1]
#     print(h)
#     if h > 0:
#         for i in range(n):
#             A[i][0] = min(A[i][0], h)
#             A[i][2] = A[i][0] / A[i][1]
#         A.sort(reverse=True)
#         A.sort(key=lambda x:x[2], reverse=True)
#     print(A)
# print(a)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])-1

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)