Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]

    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()


Fixed submission:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    ANS = []
    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    l = len(NN)
    ANS = []
    now = 0
    MIN = [0, A[0], A[0]*11, A[0]*111, A[0]*1111]
    check = 0
    for i in range(l):
        for a in A:
            if a > NN[0]:
                ANS.append(now*10**(l-i)+a*10**(l-1-i) + MIN[l-1-i])
                now = now*10+a
                break
            elif a == NN[0]:
                now = now*10+NN[0]
                check += 1
    if check == l:
        ANS.append(now)
    print( min(ANS))
            
if __name__ == '__main__':
    main()


Fixed submission:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    ANS = []
    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys


def resolve(in_):
    S = next(in_).strip()
    T = next(in_).strip()

    x = 0
    for i in range(len(S)):
        if len(S) - i < len(T):
            break
        v = 0
        for x, y in zip(S[i:], T)
            if x == y:
                v += 1
            x = max(x, len(T) - v)
    
    return x
    

def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    S = next(in_).strip()
    T = next(in_).strip()

    ans = 0
    for i in range(len(S)):
        if len(S) - i < len(T):
            break
        v = 0
        for x, y in zip(S[i:], T):
            if x == y:
                v += 1
            ans = max(ans, v)
    
    return len(T) - ans
    

def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

def resolve(in_):
    N = int(next(in_))
    A = list(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    for i, a in enumerate(A):
        v = sum(A[i + 1:])
        ans += a * v
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    v = sum(A)
    for a in A:
        v -= a
        ans += a * v
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

def resolve(in_):
    N = int(next(in_))
    A = list(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    for a, b in itertools.combinations(A, 2):
        ans += a * b
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    v = sum(A)
    for a in A:
        v -= a
        ans += a * v
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 100000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    ans = 0
    left = 0
    right = len(c) - 1
    while left < right:
        if c[left] == 'R':
            left += 1
            continue
        if c[right] == 'W':
            right -= 1
            continue
        left += 1
        right -= 1
        ans += 1

    return ans


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from math import ceil, floor

def cut_logs(x, a):
    return sum(ceil(ai / x) - 1 for ai in a)


def resolve(in_):
    n, k = map(int, next(in_).split())
    logs = tuple(map(int, next(in_).split()))  # A
    assert n == len(logs)
    max_logs = max(logs)

    lb = 0
    ub = max_logs
    while ub - lb > 1:
        mid = (ub + lb) // 2
        v = cut_logs(mid, logs)
        # print(f'{lb=} {mid=} {ub=} {v<=k=} {v=} {k=}')
        if v <= k:
            ub = mid
        else:
            lb = mid
    # print(f'end: {lb=} {mid=} {ub=} {v<=k=} {v=} {k=}')

    return ub


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

for b, c in L:
  # print(a)
  if b in a:
    a[c] += a[b]
    del a[b]
  print(sum(x * y for x, y in a.items()))



Fixed submission:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

s = sum(a)
for b, c in L:
  # print(a)
  if b in a:
    a[c] += a[b]
    del a[b]
  print(sum(x * y for x, y in a.items()))



Fixed submission:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)

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

n = int(readline())
a = list(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

s = sum(a)
for b, c in L:
  for i, v in enumerate(tuple(a)):
    if v == b:
      s -= (c - a[i])
      a[i] = c
  print(sum(a))


Fixed submission:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)

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

n = int(readline())
a = list(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

for b, c in L:
  for i, v in enumerate(tuple(a)):
    if v == b:
      a[i] = c
  print(sum(a))


Fixed submission:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline

n = int(readline())
a = list(map(int, readline().split()))

for j in range(n):
  b = 0
  for i, v in enumerate(a):
    if i != j:
      b ^= v
  print(b)

Fixed submission:
import sys
from functools import reduce
from operator import xor
readline = sys.stdin.buffer.readline

n = int(readline())
a = tuple(map(int, readline().split()))

s = reduce(xor, a[1:], a[0])
# print(s)
b = tuple(str(s ^ v) for v in a)
print(' '.join(b))
Buggy python submission (verdict: Runtime Error):
import sys

a = sys.stdin.read()
for i, v in enumerate(map(int, a.split), 1):
  if v == 0:
    print(i)
    break

Fixed submission:
import sys
 
a = sys.stdin.read()
for i, v in enumerate(map(int, a.split()), 1):
  if v == 0:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
import sys
import operator

readline = sys.stdin.buffer.readline
a, b = map(int, readline().split())
c = set(map(int, readline().split()))

L = [(i, abs(i - a)) for i in range(1, 100) if i not in c]
L.sort(key=operator.itemgetter(1))
print(L[0][0])

Fixed submission:
import sys
import operator

readline = sys.stdin.buffer.readline
a, b = map(int, readline().split())
c = set(map(int, readline().split()))

L = [(i, abs(i - a)) for i in range(0, 102) if i not in c]
L.sort(key=operator.itemgetter(1))
print(L[0][0])

Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline
a, b = map(int, readline().split())
c = set(map(int, readline().split()))

L = [(i, i - a) for i in range(1, 100) if i not in c]
L.sort(key=lambda x: abs(x[1]))
print(L[0][0])

Fixed submission:
import sys
import operator

readline = sys.stdin.buffer.readline
a, b = map(int, readline().split())
c = set(map(int, readline().split()))

L = [(i, abs(i - a)) for i in range(0, 102) if i not in c]
L.sort(key=operator.itemgetter(1))
print(L[0][0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
readline()
b = list(map(int, readline().split()))

b.sort(reverse=True)
# print(b)

x = len(b)
c = [(k, len(tuple(L))) for k, L in groupby(b)]
# print(c)
for i, v in enumerate(c):
  if v[1] > 1:
    x -= v[1]
    continue
  for vv in c[-1:i:-1]:
    # print(v[0], vv[0])
    if v[0] / 2 < vv[0]:
      break
    if not v[0] % vv[0]:
      x -= 1
      break
print(x)

Fixed submission:
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
readline()
b = list(map(int, readline().split()))

b.sort()
# print(b)

x = len(b)
c = [(k, len(tuple(L))) for k, L in groupby(b)]
# print(c)
m = c[-1][0]
# print(m)
s = [True] * (m + 1)
# print(len(s))

a = 0
for i, le in c:
  if s[i]:
    if le <= 1:
      a += 1
    for v in range(i, m + 1, i):
      s[v] = False
# print(s)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
readline()
b = list(map(int, readline().split()))

b.sort(reverse=True)
# print(b)

x = len(b)
c = [(k, len(tuple(L))) for k, L in groupby(b)]
# print(c)
for i, v in enumerate(c):
  if v[1] > 1:
    x -= v[1]
    continue
  for vv in c[-1:i:-1]:
    # print(v[0], vv[0])
    if not v[0] % vv[0]:
      x -= 1
      break
print(x)

Fixed submission:
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
readline()
b = list(map(int, readline().split()))

b.sort()
# print(b)

x = len(b)
c = [(k, len(tuple(L))) for k, L in groupby(b)]
# print(c)
m = c[-1][0]
# print(m)
s = [True] * (m + 1)
# print(len(s))

a = 0
for i, le in c:
  if s[i]:
    if le <= 1:
      a += 1
    for v in range(i, m + 1, i):
      s[v] = False
# print(s)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
a = map(int, readline().split())
b = list(map(int, readline().split()))
b.sort(reverse=True)

x = len(b)
c = [(k, len(list(L))) for k, L in groupby(b)]
for i, v in enumerate(c):
  if v[1] > 1:
    x -= v[1]
    continue
  for vv in c[i+1:]:
    if not v[0] % vv[0]:
      x -= 1
      break
print(x)

Fixed submission:
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
readline()
b = list(map(int, readline().split()))

b.sort()
# print(b)

x = len(b)
c = [(k, len(tuple(L))) for k, L in groupby(b)]
# print(c)
m = c[-1][0]
# print(m)
s = [True] * (m + 1)
# print(len(s))

a = 0
for i, le in c:
  if s[i]:
    if le <= 1:
      a += 1
    for v in range(i, m + 1, i):
      s[v] = False
# print(s)
print(a)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
a = map(int, readline().split())
a.sort()
v = 1
for i in a:
  v *= i
  if v > 1000000000000000000:
    print(-1)
    break
  elif v == 0:
    print(0)
    break
else:
  print(v)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
a.sort()
v = 1
for i in a:
  v *= i
  if v > 1000000000000000000:
    print(-1)
    break
  elif v == 0:
    print(0)
    break
else:
  print(v)
Buggy python submission (verdict: Runtime Error):
import sys


def resolve(in_):
    x = int(in_.read())
    for a in range(-118, 119 + 1):
        for b in range(-118, 119 + 1):
            if x == a ** 5 - b ** 5:
                return a, b
    raise ValueError()


def main():
    answer = resolve(sys.stdin.buffer)
    print('{} {}'.format(answer))


if __name__ == '__main__':
    main()

Fixed submission:
import sys


def resolve(in_):
    x = int(in_.read())
    for a in range(-118, 119 + 1):
        for b in range(-118, 119 + 1):
            if x == a ** 5 - b ** 5:
                return a, b
    raise ValueError()


def main():
    answer = resolve(sys.stdin.buffer)
    print('{} {}'.format(*answer))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin)
print(sum(i for i in range(1, n + 1) if i % 3 and i % 5))

Fixed submission:
import sys
n = int(sys.stdin.read())
print(sum(i for i in range(1, n + 1) if i % 3 and i % 5))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from functools import reduce
from math import gcd

n = int(sys.stdin.read())
print(sum(reduce(gcd, abc) for abc in itertools.product(range(1, n + 1), repeat=3)))

Fixed submission:
import sys
import itertools
from math import gcd

n = int(sys.stdin.read())
print(sum(gcd(gcd(abc[0], abc[1]), abc[2]) for abc in itertools.product(range(1, n + 1), repeat=3)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

def f1(v):
    i, j, k = v
    return j - i != k - j


s = b''
def f2(v):
    i, j, k = v
    si = s[i - 1]
    sj = s[j - 1]
    sk = s[k - 1]
    return si != sj and sj != sk and sk != si


def resolve(in_):
    n = int(next(in_))
    global s
    s = next(in_)

    
    it = ((i, j, k) for i in range(1, n + 1) for j in range(i, n + 1) for k in range(j, n + 1))
    it = filter(f1, it)
    it = filter(f2, it)
    ans = sum(1 for _ in it)

    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Fixed submission:
import sys
import functools
import collections
import operator


def resolve(in_):
    n = int(next(in_))
    s = next(in_).strip()

    c = collections.Counter()
    c[b'R'[0]] = 0
    c[b'G'[0]] = 0
    c[b'B'[0]] = 0
    c.update(s)
    ans = functools.reduce(operator.mul, c.values())
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            k = j * 2 - i
            if k - 1 >= n:
                break
            si = s[i - 1]
            sj = s[j - 1]
            sk = s[k - 1]
            if si != sj and sj != sk and sk != si:
                ans -= 1
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, sys.stdin.buffer.read().split())
rem = n % k
print(min(rem, k - rem)

Fixed submission:
import sys
n, k = map(int, sys.stdin.buffer.read().split())
rem = n % k
print(min(rem, k - rem))

Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, sys.stdin.buffer.read())
print(n % k)

Fixed submission:
import sys
n, k = map(int, sys.stdin.buffer.read().split())
rem = n % k
print(min(rem, k - rem))
Buggy python submission (verdict: Runtime Error):
import sys
print('Yes' if set(sys.stdin.read().strip()) >= 2 else 'No')

Fixed submission:
import sys
print('Yes' if len(set(sys.stdin.read().strip())) >= 2 else 'No')
Buggy python submission (verdict: Runtime Error):
import sys

N, K = map(int, next(sys.stdin.buffer).split())
H = sorted(map(int, next(sys.stdin.buffer).split()))

print(sum(H[:K])

Fixed submission:
import sys

N, K = map(int, next(sys.stdin.buffer).split())
H = list(map(int, next(sys.stdin.buffer).split()))

if K:
  H.sort()
  print(sum(H[:-K]))
else:
  print(sum(H))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import islice


def resolve(in_):
    H, N = map(int, next(in_).split())
    AB = tuple(tuple(map(int, line.split())) for line in islice(in_, N))
    
    dp = [1 << 31] * (H + 1)
    dp[0] = 0

    for i in range(H):
        for a, b in AB:
            ia = min(H, i + a)
            dp[ia] = min(dp[ia], dp[i] + b)

    return dp[H]


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from itertools import islice


def resolve(in_):
    H, N = map(int, next(in_).split())
    AB = tuple(tuple(map(int, line.split())) for line in islice(in_, N))
    
    dp = [1 << 31] * (H + 1)
    dp[0] = 0

    for i in range(H):
        for a, b in AB:
            ia = min(H, i + a)
            dp[ia] = min(dp[ia], dp[i] + b)

    return dp[H]


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
import functools
from math import gcd


def lcm2(x, y):
    return x * y // gcd(x, y)


def lcm(x):
    return functools.reduce(lcm2, x)


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))
    a_lcm = lcm(A)

    mod = 10 ** 9 + 7

    ans = 0
    for a in A:
        ans += a_lcm // a
        ans %= mod
            
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

H, M = map(int, next(sys.stdin.buffer).split())
print('Yes' if H == M else 'No')
Buggy python submission (verdict: Runtime Error):
import sys


def resolve(in_):
    N, M = map(int, next(in_).split())
    PS = tuple(line.strip().split() for line in in_)
    
    ac = set()
    wa = {}

    for p, s in PS:
        if s == 'AC':
            ac.add(p)
        if s == 'WA' and p not in ac:
            wa[p] = wa.setdefault(p, 0) + 1

    penalties = 0
    for k, v in wa.items:
        if k in ac:
            penalties += v
    
    return '{} {}'.format(len(ac), penalties)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    N, M = map(int, next(in_).split())
    PS = tuple(line.strip().split() for line in in_)
    
    ac = set()
    wa = {}

    for p, s in PS:
        if s == 'AC':
            ac.add(p)
        if s == 'WA' and p not in ac:
            wa[p] = wa.setdefault(p, 0) + 1

    penalties = 0
    for k, v in wa.items():
        if k in ac:
            penalties += v
    
    return '{} {}'.format(len(ac), penalties)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys


def resolve(in_):
    N, M = map(int, next(in_).split())
    PS = tuple(line.strip().split() for line in in_)
    
    ac = set()
    wa = {}

    for p, s in PS:
        if s == 'AC':
            ac.add(p)
        if s == 'WA' and p not in ac:
            wa[p] = wa.setdefault(p, 0) + 1

    penalties = 0
    for k, v in wa.items:
        if k in ac:
            penalties += v
    
    return '{} {}'.format(len(ac), penalties)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve(in_):
    N, M = map(int, next(in_).split())
    PS = tuple(line.strip().split() for line in in_)
    
    ac = set()
    wa = {}

    for p, s in PS:
        if s == 'AC':
            ac.add(p)
        if s == 'WA' and p not in ac:
            wa[p] = wa.setdefault(p, 0) + 1

    penalties = 0
    for k, v in wa.items():
        if k in ac:
            penalties += v
    
    return '{} {}'.format(len(ac), penalties)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()