Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for _ in range(N):
    inp = input()
    inp.sort()
    s = str(inp)
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))



Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for _ in range(N):
    s = str(sorted(input()))
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))

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

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for i in range(N):
    s = str(sorted(input()))
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))



Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for _ in range(N):
    s = str(sorted(input()))
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

C = [[A[0]]]
head = [A[0]]
for i in range(N-1):
    nex = A[i+1]
    for j in range(len(head)):
        if nex > head[j]:
            # C[j].append(A[i+1])
            head[j] = nex
            break
    else:        
        C.append([nex])  # new color
        head.append(nex)

print(len(C))


Fixed submission:
import bisect

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

def LIS(A):
    """
    returns Longest Increasing Subsequence of list A.
    """
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_left(B, A[i+1])
            B[index] = A[i+1]
    return B

def LDS(A):
    """
    returns Longest Decreasing Subsequence of list A.
    """
    A = A[::-1]
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_right(B, A[i+1])
            B[index] = A[i+1]
    return B[::-1]


print(len(LDS(A)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

C = [[A[0]]]
head = [A[0]]
for i in range(N-1):
    for j, h in enumerate(head):
        if A[i+1] > h:
            C[j].append(A[i+1])
            head[j] = A[i+1]
            break
    else:        
        C.append([A[i+1]])  # new color
        head.append(A[i+1])

print(len(C))


Fixed submission:
import bisect

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

def LIS(A):
    """
    returns Longest Increasing Subsequence of list A.
    """
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_left(B, A[i+1])
            B[index] = A[i+1]
    return B

def LDS(A):
    """
    returns Longest Decreasing Subsequence of list A.
    """
    A = A[::-1]
    B = [A[0]]
    for i in range(N-1):
        if A[i+1] >= B[-1]:
            B.append(A[i+1])
        else:
            index = bisect.bisect_right(B, A[i+1])
            B[index] = A[i+1]
    return B[::-1]


print(len(LDS(A)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

input = sys.stdin.readline

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

X = [0 for _ in range(N)]



X = np.array(X)
A = np.array(A)
for i in range(N):
    B  = np.hstack((A[i:N+i], A[:i]))
    X = X + (-1)**i * B
 
print(*X)

Fixed submission:
import sys

input = sys.stdin.readline

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

X = [0 for _ in range(N)]


for i in range(N):
    X[0] += (-1)**i * A[i]
for i in range(1, N):
    X[i] = -X[i-1] + 2*A[i-1]
 
 
print(*X)

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

input = sys.stdin.readline

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

X = [0 for _ in range(N)]



X = np.array(X)
A = np.array(A)
for i in range(N):
    B  = np.hstack((A[i:N+i], A[:i]))
    X = X + (-1)**i * B
 
print(*X)

Fixed submission:
import sys

input = sys.stdin.readline

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

X = [0 for _ in range(N)]


for i in range(N):
    X[0] += (-1)**i * A[i]
for i in range(1, N):
    X[i] = -X[i-1] + 2*A[i-1]
 
 
print(*X)

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

input = sys.stdin.readline

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

X = [0 for _ in range(N)]

for i in range(N):
    j = i
    f = 1
    while j < N+i:
        X[i] += f * A[j % N]
        j += 1
        f *= -1

print(*X)

Fixed submission:
import sys

input = sys.stdin.readline

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

X = [0 for _ in range(N)]


for i in range(N):
    X[0] += (-1)**i * A[i]
for i in range(1, N):
    X[i] = -X[i-1] + 2*A[i-1]
 
 
print(*X)
Buggy python submission (verdict: Runtime Error):
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1))
    a %= mod
    print(a)



Fixed submission:
from collections import defaultdict
S = input()
D = defaultdict(int)
for s in S:
    D[s] += 1

def main(D):
    if len(D.keys()) != 2:
        return 0
    else:
        for v in D.values():
            if v != 2:
                return 0
    return 1

if main(D):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = (a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1))) % mod
    print(a)



Fixed submission:
from collections import defaultdict
S = input()
D = defaultdict(int)
for s in S:
    D[s] += 1

def main(D):
    if len(D.keys()) != 2:
        return 0
    else:
        for v in D.values():
            if v != 2:
                return 0
    return 1

if main(D):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1)) % mod
    print(a)



Fixed submission:
from collections import defaultdict
S = input()
D = defaultdict(int)
for s in S:
    D[s] += 1

def main(D):
    if len(D.keys()) != 2:
        return 0
    else:
        for v in D.values():
            if v != 2:
                return 0
    return 1

if main(D):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a *= (N - K - i) * (K - (i + 1)) / ((i+2) * (i+1)) % mod
    a = int(a)
    print(a)



Fixed submission:
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1))
    print(a % mod)

Buggy python submission (verdict: Runtime Error):
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) / ((i+2) * (i+1))
    print(int(a % mod))



Fixed submission:
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1))
    print(a % mod)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

aji = [L + i for i in range(N)]

abs_aji = [abs(a) for a in aji]
index = np.argmin(abs_aji)
aji.pop(index)

print(sum(aji))

Fixed submission:
import numpy as np

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

aji = [L + i for i in range(N)]

abs_aji = [abs(a) for a in aji]
index = np.argmin(abs_aji)
aji.pop(index)

print(sum(aji))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())

A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


def yes_or_no():
    for c in C:
        if c < 0:
            return 0
    
    sorted_index = np.argsort(B)
    sum_A = [A[sorted_index[0]]]
    for i in range(1, N):
        next_num = sum_A[i-1] + A[sorted_index[i]]
        sum_A.append(next_num)
        if next_num > B[sorted_index[i]]:
            print(sum_A)
            return 0
        
    return 1

if yes_or_no():
    print("Yes")
else:
    print("No")

Fixed submission:
import numpy as np

N = int(input())

A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


def yes_or_no():
    sorted_index = np.argsort(B)
    if A[sorted_index[0]] > B[sorted_index[0]]:
        return 0
    sum_A = [A[sorted_index[0]]]
    for i in range(1, N):
        next_num = sum_A[i-1] + A[sorted_index[i]]
        sum_A.append(next_num)
        if next_num > B[sorted_index[i]]:
            return 0
        
    return 1

if yes_or_no():
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
*L, = map(int, input().split())

D = [0]
for i in range(1, N+1):
    D.append(D[i-1] + L[i-1])

num = 0
i = 0
d = D[i]
while d <= X and num < N+1:
    num += 1
    i += 1
    d = D[i]

print(num)

Fixed submission:
N, X = map(int, input().split())
*L, = map(int, input().split())

D = [0]
for i in range(1, N+1):
    D.append(D[i-1] + L[i-1])

num = 0
i = 0
d = D[i]
while d <= X and num < N+1:
    num += 1
    i += 1
    if i != N+1:
        d = D[i]

print(num)

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
*L, = map(int, input().split())

D = [0]
for i in range(1, N+1):
    D.append(D[i-1] + L[i-1])

num = 0
i = 0
d = D[i]
while d <= X:
    num += 1
    i += 1
    d = D[i]
print(num)

Fixed submission:
N, X = map(int, input().split())
*L, = map(int, input().split())

D = [0]
for i in range(1, N+1):
    D.append(D[i-1] + L[i-1])

num = 0
i = 0
d = D[i]
while d <= X and num < N+1:
    num += 1
    i += 1
    if i != N+1:
        d = D[i]

print(num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
*W, = map(int, input().split())

front = W[0]
back = sum(W) - W[0]
diff = abs(front, back)
for i in range(1, N):
  front += W[i]
  back -= W[i]
  diff = min(diff, abs(front, back))

print(diff)
  

Fixed submission:
N = int(input())
*W, = map(int, input().split())

front = W[0]
back = sum(W) - W[0]
diff = abs(front - back)
for i in range(1, N):
  front += W[i]
  back -= W[i]
  diff = min(diff, abs(front - back))

print(diff)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
B = [0 for _ in range(N+1)]
for a in A:
  B[a] = 1

dp = [-1 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2, N+1):
  if B[i-2] == 0 and B[i-1] == 1:
    dp[i] = dp[i-2]
  elif B[i-2] == 1 and B[i-1] == 0:
    dp[i] = dp[i-1]
  elif:
    dp[i] = dp[i-1] + dp[i-2]
  else:
    dp[i] = 0

print(dp[-1])


Fixed submission:
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
B = [0 for _ in range(N+1)]
for a in A:
  B[a] = 1
mod = 10**9 + 7
dp = [-1 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2, N+1):
  if B[i-2] == 0 and B[i-1] == 1:
    dp[i] = dp[i-2]
  elif B[i-2] == 1 and B[i-1] == 0:
    dp[i] = dp[i-1]
  elif B[i-2] == 0 and B[i-1] == 0:
    dp[i] = dp[i-1] + dp[i-2]
  else:
    dp[i] = 0
  dp[i] %= mod
 
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append([tmp[1:]])
P = list(map(int, input().split()))


origin_list = [0, 1]
all_way = []
for i in itertools.product(origin_list, repeat=N):
    all_way.append(i)

ans = 0
for way in all_way:
    light = 0
    for i, s in enumerate(S):
        small_sum = 0
        for ss in s:
            if way[ss - 1] == 1:
                small_sum += 1
        if small_sum % 2 == P[i]:
            light += 1
    if light == M:
        ans += 1

print(ans)

Fixed submission:
import itertools

N, M = map(int, input().split())
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append([tmp[1:]])
P = list(map(int, input().split()))


origin_list = [0, 1]
all_way = []
for i in itertools.product(origin_list, repeat=N):
    all_way.append(i)

ans = 0
for way in all_way:
    light = 0
    for i, s in enumerate(S):
        small_sum = 0
        for ss in s:
            for sss in ss:
                if way[sss - 1] == 1:
                    small_sum += 1
            if small_sum % 2 == P[i]:
                light += 1
        if light == M:
            ans += 1

print(ans)

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

N, M = map(int, input().split())
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append([tmp[1:]])
P = list(map(int, input().split()))


origin_list = [0, 1]
all_way = []
for i in itertools.product(origin_list, repeat=N):
    all_way.append(i)
print(all_way)

ans = 0
for way in all_way:
    light = 0
    for i, s in enumerate(S):
        small_sum = 0
        for ss in s:
            if way[ss - 1] == 1:
                small_sum += 1
        if small_sum % 2 == P[i]:
            light += 1
    if light == M:
        ans += 1

print(ans)

Fixed submission:
import itertools

N, M = map(int, input().split())
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append([tmp[1:]])
P = list(map(int, input().split()))


origin_list = [0, 1]
all_way = []
for i in itertools.product(origin_list, repeat=N):
    all_way.append(i)

ans = 0
for way in all_way:
    light = 0
    for i, s in enumerate(S):
        small_sum = 0
        for ss in s:
            for sss in ss:
                if way[sss - 1] == 1:
                    small_sum += 1
            if small_sum % 2 == P[i]:
                light += 1
        if light == M:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


import numpy as np
import bisect

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
A.sort()
for _ in range(M):
    b, c = map(int, input().split())
    index = bisect.bisect_left(A, c)
    edge = max(0, index - b)
    A[:edge] = A[index-edge:index]
    A[edge:index] = c

print(sum(A))


Fixed submission:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] += b
    

key = sorted(list(d.keys()))

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    n = d[key[i]]
    num -= n
    S += key[i] * n
    
S += key[i] * num

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


import numpy as np
import bisect

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
A.sort()
for _ in range(M):
    b, c = map(int, input().split())
    index = bisect.bisect_left(A, c)
    edge = max(0, index - b)
    A[:edge] = A[index-edge:index]
    A[edge:index] = c

print(sum(A))


Fixed submission:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] += b
    

key = sorted(list(d.keys()))

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    n = d[key[i]]
    num -= n
    S += key[i] * n
    
S += key[i] * num

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))


for i in range(M):
    b, c = map(int, input().split())
    A += [c] * b

A.sort()
sum = 0
for i in range(N):
    sum += A.pop()
print(sum)

Fixed submission:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] += b
    

key = sorted(list(d.keys()))

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    n = d[key[i]]
    num -= n
    S += key[i] * n
    
S += key[i] * num

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))


for i in range(M):
    b, c = map(int, input().split())
    A += [c] * b

A = sorted(A)
print(sum(A[-N:]))

Fixed submission:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] += b
    

key = sorted(list(d.keys()))

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    n = d[key[i]]
    num -= n
    S += key[i] * n
    
S += key[i] * num

print(S)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = map(int, input().split())
C = map(int, input().split())

answer = 0
for i in range(N):
  if V[i] > C[i]:
    answer += V[i] - C[i]

print(int(answer))

Fixed submission:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

answer = 0
for i in range(N):
  if V[i] > C[i]:
    answer += V[i] - C[i]

print(int(answer))
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import fractions

N = int(input())
A = list(map(int, input().split()))
answer = 0
for i in range(N):
  tmp = A.copy()
  tmp.pop(i)
  gcd = functools.reduce(fractions.gcd, tmp)
  
  if answer < gcd:
    answer = gcd

print(int(answer))


Fixed submission:
import fractions

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

L, R = [0], [0]
for i in range(N):
    L.append(fractions.gcd(L[i], A[i]))
    R.append(fractions.gcd(R[i], A[-i-1]))
L.append(0)
R.append(0)
R = R[::-1]

M = []
for i in range(N):
    M.append(fractions.gcd(L[i], R[i+2]))
print(max(M))

Buggy python submission (verdict: Runtime Error):
import functools
import math

N = int(input())
A = list(map(int, input().split()))
answer = 0
for i in range(N):
  tmp = A.copy()
  tmp.pop(i)
  gcd = functools.reduce(math.gcd, tmp)
  
  if answer < gcd:
    answer = gcd

print(int(answer))

Fixed submission:
import fractions

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

L, R = [0], [0]
for i in range(N):
    L.append(fractions.gcd(L[i], A[i]))
    R.append(fractions.gcd(R[i], A[-i-1]))
L.append(0)
R.append(0)
R = R[::-1]

M = []
for i in range(N):
    M.append(fractions.gcd(L[i], R[i+2]))
print(max(M))
Buggy python submission (verdict: Runtime Error):
import numpy as np

s = str(input())

y, m, d = s.split("/")

y, m, d = int(y), int(m), int(d)

if y < 2019:
  print("Heisei")
elif y==2019 and m<4:
  print("Heisei")
elif y==2019 and m=4 and d < 30:
  print("Heisei")
else:
  print("TBD")

Fixed submission:
import numpy as np

s = str(input())
y, m, d = s.split("/")

y, m, d = int(y), int(m), int(d)

if y < 2019:
  print("Heisei")
elif y==2019 and m<4:
  print("Heisei")
elif y==2019 and m==4 and d <= 30:
  print("Heisei")
else:
  print("TBD")
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

temp = []
for s in input:
  v, k = s.split()
  if k == "BTC":
    temp.append(float(v)*380000)
  else:
    temp.append(float(v))

print(sum(temp))
  

Fixed submission:

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

temp = []
for s in input:
  v, k = s.split()
  if k == "BTC":
    temp.append(float(v)*380000)
  else:
    temp.append(float(v))

print(sum(temp))
Buggy python submission (verdict: Runtime Error):

N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
	for j in range(W + 1):
		# 品物(w[i],v[i])を選ぶとき、j-w[i]>=0に限って、価値v[i]が加算される
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		# 品物(w[i],v[i])を選ばないとき、何も加算しない
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Fixed submission:
#pypy3でAC

import sys
def input():
    return sys.stdin.readline()[:-1]

N, W = map(int, input().split())
w, v = [], []
for i in range(1, N+1):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

V = sum(v)
#i個目までの品物から価値がj以上になるように選んだときの重さの最小値
dp = [[float("inf")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
"""
i番目を選ぶ場合
dp[i][j] = dp[i-1][j-v] + w
i番目を選ばない場合
dp[i][j] = dp[i-1][j]
"""

for i in range(1, N+1):
    for j in range(V+1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
        else:
            dp[i][j] = dp[i-1][j]

# dp[N][j]がW以下であるような最大のjを探す
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j
print(ans)

Buggy python submission (verdict: Runtime Error):
# import numpy as np

# N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
# """
# dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
#          = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
# """
# for i in range(1, N+1):
#     wi, vi = map(int, input().split())
#     for k in range(1, i+1):
#         tmp = np.maximum(dp[i-k, :W-wi+1] + vi, dp[i-k, wi:W+1])
#         dp[i, wi:W+1] = np.maximum(dp[i, wi:W+1], tmp)
    

# print(int(dp[-1,-1]))


N, W = map(int, input().split())
# dp = np.zeros((N+1, W+1))  #i個目の品物までで重さw以下のときの価値の最大値 
dp = [[0]*(W+1) for _ in range(N+1)]
"""
dp[i, wi:W+1] = max(i番目の重さwiの品物を入れた場合, 入れなかった場合)
         = np.max(dp[i-1, :W-wi+1] + v, dp[i-1, wi:W+1])
"""

for i in range(1, N+1):
    w, v = map(int, input().split())

    for j in range(W+1):
        if j - w >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])


Fixed submission:
#pypy3でAC

import sys
def input():
    return sys.stdin.readline()[:-1]

N, W = map(int, input().split())
w, v = [], []
for i in range(1, N+1):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

V = sum(v)
#i個目までの品物から価値がj以上になるように選んだときの重さの最小値
dp = [[float("inf")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
"""
i番目を選ぶ場合
dp[i][j] = dp[i-1][j-v] + w
i番目を選ばない場合
dp[i][j] = dp[i-1][j]
"""

for i in range(1, N+1):
    for j in range(V+1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
        else:
            dp[i][j] = dp[i-1][j]

# dp[N][j]がW以下であるような最大のjを探す
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j
print(ans)
Buggy python submission (verdict: Runtime Error):
string = input()
i = 1
ans = "
for s in string:
  if i % 2 != 0:
    ans += s

print(ans)

Fixed submission:
string = input()
i = 1
ans = ""
for s in string:
  if i % 2 != 0:
    ans += s
  i += 1
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) - 1 for _ in range(N)]

pushed = []

def main(start=0):
     count = 0
     ls = start
     while True:
          if ls == 1:
               return count
          elif ls in pushed:
               return -1

          pushed.append(ls)
          count += 1
          ls = A[ls]

print(main())

Fixed submission:
from collections import defaultdict

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

def main():
    count = defaultdict(int)

    v = 1
    ans = 0
    while True:
        if count[v] != 0:
            return -1
        count[v] = 1
        v = A[v]
        ans += 1
        if v == 2:
            return ans

print(main())