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

MOD = 10 ** 9 + 7

N, K = map(int, input().split())

F = {}
def fact_power(a, b):
    if (a, b) in F:
        return F[(a, b)]
    if b == 0:
        ans = 1
    elif b % 2 == 0:
        d = fact_power(a, b // 2)
        ans = (d * d) % MOD
    else:
        ans = (factorial(a) * fact_power(a, b - 1)) % MOD
    F[(a, b)] = ans
    return ans

P = {}
def perm(a, b):
    if b == 0 or a < b:
        return 0
    if (a, b) in P:
        return P[(a, b)]
    ans = fact_power(a - 1, 1) * fact_power(a - b, MOD - 2) * fact_power(b - 1, MOD - 2) % MOD
    P[(a, b)] = ans
    return ans

if N == K:
    print(1)
    for i in range(K - 1):
        print(0)
else:
    for i in range(1, K + 1):
        B = perm(K, i)
        R = perm(N - K, i - 1) + perm(N - K, i) * 2 + perm(N - K, i + 1)
        print(B * R % MOD)


Fixed submission:
from math import factorial

MOD = 10 ** 9 + 7

N, K = map(int, input().split())

f = {}
def fact(x):
    if x in f:
        return f[x]
    ans = factorial(x)
    f[x] = ans
    return ans

F = {}
def fact_power(a, b):
    if (a, b) in F:
        return F[(a, b)]
    if b == 0:
        ans = 1
    elif b % 2 == 0:
        d = fact_power(a, b // 2)
        ans = (d * d) % MOD
    else:
        ans = (fact(a) * fact_power(a, b - 1)) % MOD
    F[(a, b)] = ans
    return ans

P = {}
def perm(a, b):
    if b == 0 or a < b:
        return 0
    if (a, b) in P:
        return P[(a, b)]
    ans = fact_power(a - 1, 1) * fact_power(a - b, MOD - 2) * fact_power(b - 1, MOD - 2) % MOD
    P[(a, b)] = ans
    return ans

if N == K:
    print(1)
    for i in range(K - 1):
        print(0)
else:
    for i in range(1, K + 1):
        B = perm(K, i)
        R = perm(N - K, i - 1) + perm(N - K, i) * 2 + perm(N - K, i + 1)
        print(B * R % MOD)
Buggy python submission (verdict: Runtime Error):
import fractions

A, B, C, D = map(int, input().split())
lcm = C * D // math.gcd(C, D)

def f(n):
    return n - (n // C + n // D - n // lcm)

print(f(B) - f(A - 1))


Fixed submission:
import fractions

A, B, C, D = map(int, input().split())
lcm = C * D // fractions.gcd(C, D)

def f(n):
    return n - (n // C + n // D - n // lcm)

print(f(B) - f(A - 1))
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
a = [-1] + [int(input()) for i in range(M)] + [N + 1]

factorial = {0: 1}
f = 1
for i in range(1, N):
    f *= i
    factorial[i] = f

c = {}
def nCr(n, r):
    if (n, r) in c:
        return c[(n, r)]
    a = factorial[n] // (factorial[n - r] * factorial[r])
    c[(n, r)] = a
    return a

d = {}
def step(n):
    if n in d:
        return d[n]
    a = 0
    for k in range(n // 2 + 1):
        a += nCr(n - k, k)
    d[n] = a
    return a

ans = 1
for i in range(M + 1):
    n = a[i + 1] - a[i] - 2
    if n < 0:
        ans = 0
    else:
        ans *= step(n)
print(ans % MOD)


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
a = defaultdict(lambda: True)
for i in range(M):
    a[int(input())] = False

dp = defaultdict(int)
dp[0] = 1
for i in range(1, N + 1):
    if a[i]:
        dp[i] = dp[i - 1] + dp[i - 2]
print(dp[N] % (10 ** 9 + 7))

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

MOD = 10 ** 9 + 7

N, M = map(int, input().split())
a = [-1] + [int(input()) for i in range(M)] + [N + 1]

c = {}
def nCr(n, r):
    if (n, r) in c:
        return c[(n, r)]
    a = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    c[(n, r)] = a
    return a

d = {}
def step(n):
    if n in d:
        return d[n]
    a = 0
    for k in range(n // 2 + 1):
        a += nCr(n - k, k)
    d[n] = a
    return a

ans = 1
for i in range(M + 1):
    n = a[i + 1] - a[i] - 2
    if n < 0:
        ans = 0
    else:
        ans *= step(n)
print(ans % MOD)


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
a = defaultdict(lambda: True)
for i in range(M):
    a[int(input())] = False

dp = defaultdict(int)
dp[0] = 1
for i in range(1, N + 1):
    if a[i]:
        dp[i] = dp[i - 1] + dp[i - 2]
print(dp[N] % (10 ** 9 + 7))

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

MOD = 10 ** 9 + 7

N, M = map(int, input().split())
a = [-1] + [int(input()) for i in range(M)] + [N + 1]

c = {}
def nCr(n, r):
    if (n, r) in c:
        return c[(n, r)]
    a = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    c[(n, r)] = a
    return a

d = {}
def step(n):
    if n in d:
        return d[n]
    a = 0
    for k in range(n // 2 + 1):
        a += nCr(n - k, k)
    d[n] = a
    return a

ans = 1
for i in range(M + 1):
    n = a[i + 1] - a[i] - 2
    if n < 0:
        ans = 0
    else:
        ans *= step(n)
        ans %= MOD
print(ans)


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
a = defaultdict(lambda: True)
for i in range(M):
    a[int(input())] = False

dp = defaultdict(int)
dp[0] = 1
for i in range(1, N + 1):
    if a[i]:
        dp[i] = dp[i - 1] + dp[i - 2]
print(dp[N] % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))

ans = 0
while q:
    nq = deque()
    while q:
        h, w = q.popleft()
        if h > 0 and A[h - 1][w] == '.':
            A[h - 1][w] = '#'
            nq.append((h - 1, w))
        if h < H - 1 and A[h + 1][w] == '.':
            A[h + 1][w] = '#'
            nq.append((h + 1, w))
        if w > 0 and A[h][w - 1] == '.':
            A[h][w - 1] = '#'
            nq.append((h, w - 1))
        if w < W - 1 and A[h][w + 1] == '.':
            A[h][w + 1] = '#'
            nq.append((h, w + 1))
    if not nq:
        break
    q = nq
    ans += 1
print(ans)


Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))

ans = 0
while q:
    nq = deque()
    while q:
        h, w = q.popleft()
        if h > 0 and A[h - 1][w] == '.':
            A[h - 1][w] = '#'
            nq.append((h - 1, w))
        if h < H - 1 and A[h + 1][w] == '.':
            A[h + 1][w] = '#'
            nq.append((h + 1, w))
        if w > 0 and A[h][w - 1] == '.':
            A[h][w - 1] = '#'
            nq.append((h, w - 1))
        if w < W - 1 and A[h][w + 1] == '.':
            A[h][w + 1] = '#'
            nq.append((h, w + 1))
    if not nq:
        break
    q = nq
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
    cum_left.append(gcd(cum_left[-1], A[i]))
    cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))

ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
    ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)


Fixed submission:
from fractions import gcd

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

cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
    cum_left.append(gcd(cum_left[-1], A[i]))
    cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))

ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
    ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

positions = []
prev_A = False
for j in range(N):
    if S[j] == 'A':
        prev_A = True
    elif prev_A == True and S[j] == 'C':
        positions.append(j - 1)
        prev_A = False
    else:
        prev_A = False

for i in range(Q):
    l, r = map(int, input().split())
    print(len(list(filter(lambda x: l - 1 <= x < r - 1, positions))))


Fixed submission:
N, Q = map(int, input().split())
S = input()

c = [0]
for j in range(1, N):
    if S[j - 1] == 'A' and S[j] == 'C':
        c.append(c[-1] + 1)
    else:
        c.append(c[-1])

# 0 1 1 1 2 2 3
# A C A A C A C
# 1 2 3 4 5 6 7
for i in range(Q):
    l, r = map(int, input().split())
    print(c[r - 1] - c[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for i in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    prev_A = False
    for j in range(l - 1, r):
        if S[j] == 'A':
            prev_A = True
        elif prev_A == True and S[j] == 'C':
            cnt += 1
            prev_A = False
        else:
            prev_A = False
    print(cnt)


Fixed submission:
N, Q = map(int, input().split())
S = input()

c = [0]
for j in range(1, N):
    if S[j - 1] == 'A' and S[j] == 'C':
        c.append(c[-1] + 1)
    else:
        c.append(c[-1])

# 0 1 1 1 2 2 3
# A C A A C A C
# 1 2 3 4 5 6 7
for i in range(Q):
    l, r = map(int, input().split())
    print(c[r - 1] - c[l - 1])
Buggy python submission (verdict: Runtime Error):
import math

A, B, K = map(int, input().split())

gcd = math.gcd(A, B)
order = 0
for i in range(gcd, 0, -1):
    if gcd % i == 0:
        order += 1
        if order == K:
            print(i)
            break


Fixed submission:
import fractions

A, B, K = map(int, input().split())

gcd = fractions.gcd(A, B)
order = 0
for i in range(gcd, 0, -1):
    if gcd % i == 0:
        order += 1
        if order == K:
            print(i)
            break
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N, M = map(int, input().split())
cities = []
prefs = defaultdict(list)
for i in range(M):
    city = tuple(map(int, input().split()))
    cities.append(city)
    prefs[city[0]].append(city[1])

for pref in prefs.values():
    pref.sort()
for c in cities:
    x = prefs[c[0]].index(c[1]) + 1
    print('{:06}{:06}'.format(c[0], x))


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
years = defaultdict(list)
Q = []
for i in range(M):
    P, Y = map(int, input().split())
    years[P].append(Y)
    Q.append((P, Y))

rev_list = {}
for P, Y in years.items():
    Y.sort()
    rev_list[P] = {}
    for i in range(len(Y)):
        rev_list[P][Y[i]] = i + 1

for q in Q:
    print('{:06}{:06}'.format(q[0], rev_list[q[0]][q[1]]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
cities = []
prefs = defaultdict(list)
for i in range(M):
    city = tuple(map(int, input().split()))
    cities.append(city)
    prefs[city[0]].append(city[1])

for pref in prefs.values():
    pref.sort()
for c in cities:
    x = prefs[c[0]].index(c[1]) + 1
    print(f'{c[0]:06}{x:06}')


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
years = defaultdict(list)
Q = []
for i in range(M):
    P, Y = map(int, input().split())
    years[P].append(Y)
    Q.append((P, Y))

rev_list = {}
for P, Y in years.items():
    Y.sort()
    rev_list[P] = {}
    for i in range(len(Y)):
        rev_list[P][Y[i]] = i + 1

for q in Q:
    print('{:06}{:06}'.format(q[0], rev_list[q[0]][q[1]]))
Buggy python submission (verdict: Runtime Error):
from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

G = gcd(N, M)
L = N * M // G
n = N // G
m = M // G

ans = True
for k in range(G):
    if S[k * n] != T[k * m]:
        ans = False
        break
print(L if ans else -1)


Fixed submission:
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

G = gcd(N, M)
L = N * M // G
n = N // G
m = M // G

ans = True
for k in range(G):
    if S[k * n] != T[k * m]:
        ans = False
        break
print(L if ans else -1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from functools import reduce
from operator import mul

MOD = 10 ** 9 + 7

def nCr(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(1, r + 1))

def nHr(n, r):
    return nCr(n + r - 1, r)

N, M = map(int, input().split())

factors = defaultdict(int)
i = 2
while M > 1:
    while M % i == 0:
        M //= i
        factors[i] += 1
    i += 1

ans = 1
for n in factors.values():
    ans *= nHr(N, n)
    ans %= MOD
print(ans)


Fixed submission:
from collections import defaultdict
from functools import reduce
from operator import mul

MOD = 10 ** 9 + 7

def nCr(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(1, r + 1))

N, M = map(int, input().split())

factors = defaultdict(int)
i = 2
while M > 1 and i * i <= M:
    while M % i == 0:
        M //= i
        factors[i] += 1
    i += 1 if i == 2 else 2
if M > 1:
    factors[M] += 1

ans = 1
for n in factors.values():
    ans *= nCr(N + n - 1, n)
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from math import factorial

MOD = 10 ** 9 + 7

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

def nHr(n, r):
    return nCr(n + r - 1, r)

N, M = map(int, input().split())

factors = defaultdict(int)
i = 2
while M > 1:
    while M % i == 0:
        M //= i
        factors[i] += 1
    i += 1

ans = 1
for n in factors.values():
    ans *= nHr(N, n)
    ans %= MOD
print(ans)


Fixed submission:
from collections import defaultdict
from functools import reduce
from operator import mul

MOD = 10 ** 9 + 7

def nCr(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(1, r + 1))

N, M = map(int, input().split())

factors = defaultdict(int)
i = 2
while M > 1 and i * i <= M:
    while M % i == 0:
        M //= i
        factors[i] += 1
    i += 1 if i == 2 else 2
if M > 1:
    factors[M] += 1

ans = 1
for n in factors.values():
    ans *= nCr(N + n - 1, n)
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

original_w = []
prev = 0
for i in range(N):
    if S[i] == 'W':
        prev += 1
    original_w.append(prev)

original_e = []
prev = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'E':
        prev += 1
    original_e.insert(0, prev)

print(min([original_w[i - 1] + original_e[i + 1] for i in range(1, N - 1)] + [original_e[1], original_w[N - 2]]))


Fixed submission:
N = int(input())
S = input()

original_w = []
prev = 0
for i in range(N):
    if S[i] == 'W':
        prev += 1
    original_w.append(prev)

original_e = []
prev = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'E':
        prev += 1
    original_e.append(prev)

ans = min(original_e[N - 1], original_w[N - 2])
for i in range(1, N - 1):
    ans = min(ans, original_w[i - 1] + original_e[N - (i + 1)])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())

S = [''] * N


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        print(i)
        sys.exit()
    S[i] = s
    return s


query(0)
query(N - 1)
l = 0
r = N - 1
while r - l >= 2:
    m = (l + r) // 2
    if r - l == 2 and S[l] != S[r]:
        break
    query(m)
    if (m - l) % 2 == 0 and S[l] != S[m]:
        r = m
    else:
        l = m

for i in range(l, r + 1):
    if S[i] == '':
        print(i)
        break


Fixed submission:
import sys

N = int(input())

S = [''] * N


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        print(i)
        sys.exit()
    S[i] = s
    return s


query(0)
query(N - 1)
l = 0
r = N - 1
while r - l >= 2:
    m = (l + r) // 2
    if r - l == 2 and S[l] != S[r]:
        break
    query(m)
    if (m - l) % 2 == 0 and S[l] != S[m] or (m - l) % 2 == 1 and S[l] == S[m]:
        r = m
    else:
        l = m

for i in range(l, r + 1):
    if S[i] == '':
        print(i)
        break

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

N = int(input())


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        print(i)
        sys.exit()
    return s


S = [''] * N
S[0] = query(0)
S[N - 1] = query(N - 1)
l = 0
r = N - 1
while r - l > 0:
    m = (l + r) // 2
    if r - l == 2 and S[l] != S[r]:
        break
    S[m] = query(m)
    if (m - l) % 2 == 0 and S[l] != S[m]:
        r = m - 1
    else:
        l = m + 1
print(m)


Fixed submission:
import sys

N = int(input())

S = [''] * N


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        print(i)
        sys.exit()
    S[i] = s
    return s


query(0)
query(N - 1)
l = 0
r = N - 1
while r - l >= 2:
    m = (l + r) // 2
    if r - l == 2 and S[l] != S[r]:
        break
    query(m)
    if (m - l) % 2 == 0 and S[l] != S[m] or (m - l) % 2 == 1 and S[l] == S[m]:
        r = m
    else:
        l = m

for i in range(l, r + 1):
    if S[i] == '':
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
S = input()
S[3] = '8'
print(S)


Fixed submission:
S = list(input())
S[3] = '8'
print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())

for h, n in combinations(range(1, 3501), 2):
    num = N * h * n
    denom = 4 * h * n - N * n - N * h
    if denom > 0 and num % denom == 0:
        w = num // denom
        break
print(h, n, w)


Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        num = N * h * n
        denom = 4 * h * n - N * n - N * h
        if denom > 0 and num % denom == 0:
            w = num // denom
            break
    else:
        continue
    break
print(h, n, w)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        num = N * h * n
        denom = 4 * h * n - N * n - N * h
        if denom > 0 and num % denom == 0:
            w = num // denom
            break
    else:
        continue
    break
print(h, n, w)


Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        num = N * h * n
        denom = 4 * h * n - N * n - N * h
        if denom > 0 and num % denom == 0:
            w = num // denom
            break
    else:
        continue
    break
print(h, n, w)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())

ans = False
for n in range(N + 1):
    if (M * n - K) % (2 * n - N) == 0:
        ans = True
        break
print('Yes' if ans else 'No')


Fixed submission:
N, M, K = map(int, input().split())

ans = False
for n in range(N + 1):
    for m in range(M + 1):
        if n * (M - m) + m * (N - n) == K:
            ans = True
            break
    else:
        continue
    break
print('Yes' if ans else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

paper = []
for i in range(N):
    A = int(input())
    if A in paper:
        paper.remove(A)
    else:
        paper.append(A)
print(len(paper))


Fixed submission:
from collections import defaultdict
N = int(input())

paper = defaultdict(int)
for i in range(N):
    A = int(input())
    paper[A] += 1

ans = 0
for k, v in paper.items():
    if v % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = reduce(gcd, A)
print('POSSIBLE' if K <= max(A) and K % d == 0 else 'IMPOSSIBLE')


Fixed submission:
from fractions import gcd
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = reduce(gcd, A)
print('POSSIBLE' if K <= max(A) and K % d == 0 else 'IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for i in range(N)]

pushed = [0]
ans = 0
current = 0
while True:
    ans += 1
    current = a[current] - 1
    if current in pushed:
        ans = -1
        break
    if current == 1:
        break
    pushed.append(current)
print(ans)


Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]

pushed = [False] * N
ans = 0
current = 0
while True:
    ans += 1
    current = a[current] - 1
    if pushed[current]:
        ans = -1
        break
    if current == 1:
        break
    pushed[current] = True
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')


Fixed submission:
A, B, C = input().split()
print('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N, W = map(int, input().split())

MAX_NUM = []
len_weights = 0
def dfs(nums):
    if len(nums) == len_weights:
        sum_w = 0
        value = 0
        for i in range(len_weights):
            sum_w += weights[i] * nums[i]
            value += sum(items[weights[i]][0:nums[i]])
        return value if sum_w <= W else 0
    value = 0
    i = len(nums)
    for j in range(MAX_NUM[i] + 1):
        value = max(value, dfs(nums + [j]))
    return value

items = defaultdict(list)
for i in range(N):
    w, v = map(int, input().split())
    items[w].append(v)

for v in items.values():
    v.sort(reverse=True)

weights = sorted(items.keys())
len_weights = len(weights)
for w in weights:
    MAX_NUM.append(W // w)
print(dfs([]))


Fixed submission:
from collections import defaultdict

N, W = map(int, input().split())

MAX_NUM = []
len_weights = 0
def dfs(nums):
    if len(nums) == len_weights:
        sum_w = 0
        value = 0
        for i in range(len_weights):
            sum_w += weights[i] * nums[i]
            if nums[i] >= 1:
                value += items[weights[i]][nums[i] - 1]
        return value if sum_w <= W else 0
    value = 0
    i = len(nums)
    for j in range(MAX_NUM[i] + 1):
        value = max(value, dfs(nums + [j]))
    return value

items = defaultdict(list)
for i in range(N):
    w, v = map(int, input().split())
    items[w].append(v)

for v in items.values():
    v.sort(reverse=True)
    for i in range(1, len(v)):
        v[i] = v[i - 1] + v[i]

weights = sorted(items.keys())
len_weights = len(weights)
for w in weights:
    MAX_NUM.append(min(W // w, len(items[w])))
print(dfs([]))
Buggy python submission (verdict: Runtime Error):
s1, s2, s3 = map(int, input().split())
print(s1[0].upper() + s2[0].upper() + s3[0].upper())

Fixed submission:
s1, s2, s3 = input().split()
print(s1[0].upper() + s2[0].upper() + s3[0].upper())
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

a = 14 if A == 1 else A
b = 14 if b == 1 else B
print('Alice' if a > b else 'Bob' if a < b else 'Draw')


Fixed submission:
A, B = map(int, input().split())

a = 14 if A == 1 else A
b = 14 if B == 1 else B
print('Alice' if a > b else 'Bob' if a < b else 'Draw')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T, A = 0, 0
for i in range(N):
    Ti, Ai = map(int, input().split())
    t, a = Ti, Ai
    while t < T or a < A:
        t += Ti
        a += Ai
    T, A = t, a
print(T + A)


Fixed submission:
N = int(input())
T, A = map(int, input().split())
for i in range(N - 1):
    Ti, Ai = map(int, input().split())
    mt = T // Ti + (1 if T % Ti > 0 else 0)
    ma = A // Ai + (1 if A % Ai > 0 else 0)
    m = max(mt, ma)
    Ti *= m
    Ai *= m
    T, A = Ti, Ai
print(T + A)
Buggy python submission (verdict: Runtime Error):
S = input()

N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    bit = ('{:0' + str(N - 1) + 'b}').format(i)
    formula = S[0]
    for j in range(len(bit)):
        if bit[j] == '1':
            formula += '+'
        formula += S[j + 1]
    ans += eval(formula)
print(ans)


Fixed submission:
S = input()

N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    bit = '{:010b}'.format(i)[11 - N:]
    formula = S[0]
    for j in range(len(bit)):
        if bit[j] == '1':
            formula += '+'
        formula += S[j + 1]
    ans += eval(formula)
print(ans)