Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = {}
ans = 0
for a in input().split():
    a = int(a)
    if a not in A:
        A[a] = 1
    else:
        A[a] += 1
    ans += a
    
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    ans += (C-B) * A[B]
    if C not in A:
        A[C] = A[B]
    else:
        A[C] += A[B]
    A[B] = 0
    print(ans)

Fixed submission:
N = int(input())
A = {}
ans = 0
for a in input().split():
    a = int(a)
    if a not in A:
        A[a] = 1
    else:
        A[a] += 1
    ans += a
    
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    if B in A:
        ans += (C-B) * A[B]
        if C not in A:
            A[C] = A[B]
        else:
            A[C] += A[B]
        A[B] = 0
        print(ans)
    else:
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")

Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

for i in range(N):
    print(ans[i], end=" ")

Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

for i in range(N):
    print(ans[i], end=" ")

Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

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

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

else:
    print(ans)

Fixed submission:
N = int(input())
A = sorted([int(i) for i in input().split()])

ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        break

else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = [int(i) for i in input().split()]

roads = [[int(i) for i in input().split()] for j in range(M)]
roads2 = [[] for i in range(N)]

for spots in roads:
    roads2[spots[0]-1].append(spots[1])
    roads2[spots[1]-1].append(spots[0])

memo = []
def search(i, memo):
    memo.append(i)
    for spot in roads2[i-1]:
        if H[i-1] <= H[spot-1]:
            return 0
        
        if spot not in memo:
            search(spot, memo)
            memo.pop()
    return 1

ans = 0
for i in range(1, N+1):
    ans += search(i, memo)

print(ans)

Fixed submission:
N, M = map(int, input().split())
H = [int(i) for i in input().split()]

roads = [[int(i) for i in input().split()] for j in range(M)]
roads2 = [[] for i in range(N)]

for spots in roads:
    roads2[spots[0]-1].append(spots[1])
    roads2[spots[1]-1].append(spots[0])

ans = 0
for spot in range(1, N+1):
    good = True
    for i in roads2[spot-1]:
        if H[spot-1] <= H[i-1]:
            good = False
            break
    if good:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
q = [[int(i) for i in input().split()] for j in range(Q)]

def check(num):
    pre = 0
    for i in range(len(num)):
        if num[i] == 0:
            continue
        if num[i] <= pre:
            return False
        if num[i] > M:
            return False
    else:
        return True

ans = 0
for pattern in range(1 << Q):
    ls = []
    for i in range(Q):
        if pattern & (1 << i):
            ls.append(q[i])
    
    num = [0] * N
    ls = sorted(ls)
    score = 0
    for a, b, c, d in ls:
        if num[a-1] == 0 and num[b-1] == 0:
            num[a-1] = 1
            num[b-1] = c + 1
        elif num[a-1] == 0:
            num[a-1] = num[b-1] - c
        elif num[b-1] == 0:
            num[b-1] = num[a-1] + c
        else:
            if num[b-1] - num[a-1] != c:
                break

        if check(num): score += d
        else: break
    else:
        ans = max(ans, score)

print(ans)

Fixed submission:
import copy

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

def dfs(count, pre, ls):
    if count == N:
        temp = copy.copy(ls)
        num.append(temp)
        return

    for n in range(pre, M+1):
        ls[count] = n
        dfs(count+1, n, ls)
        ls[count] = 0

num = []
ls = [0] * N
dfs(0, 1, ls)

q = [[int(i) for i in input().split()] for j in range(Q)]
ans = 0
for i in range(len(num)):
    n = num[i]
    score = 0
    for j in range(Q):
        a, b, c, d = q[j]
        if n[b-1] - n[a-1] != c:
            continue
        score += d
    else:
        ans = max(ans, score)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

ans = 0
for i in range(len(S)-3):
    for j in range(i+3, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1
print(ans)

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

if W >= S:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for i in range(N)]

gacha_list = []
for i in S:
    if i not in gacha_list:
        gacha_list.append(i)

print(len(gacha_list))

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

ans = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
day_cost = [int(i) for i in input().split()]
holidays = N-sum(day_cost)

if holidays > 0:
    print(holidays)
else:
    print-1

Fixed submission:
N, M = map(int, input().split())
day_cost = [int(i) for i in input().split()]
holidays = N-sum(day_cost)

if holidays >= 0:
    print(holidays)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = [int(i) for i in input().split()]

for i in range(1, N+1):
    print(a_list.count(i))

Fixed submission:
N = int(input())
a_list = [i for i in input().split()]
result = [0 for i in range(1, N+1)]

for i in a_list:
    result[int(i)-1] += 1

for a in result:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = [int(i) for i in input().split()]

for i in range(1, N+1):
    a_sum = len([j for j in a_list if j == i])
    print(a_sum)

Fixed submission:
N = int(input())
a_list = [i for i in input().split()]
result = [0 for i in range(1, N+1)]

for i in a_list:
    result[int(i)-1] += 1

for a in result:
    print(a)
Buggy python submission (verdict: Runtime Error):
# 最大公約数を格納するリストを初期化
max_codiv = []
 
# 繰り返す数を入力
n = int(input())
 
import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
    for j in range(1, n+1):
    	i_j = math.gcd(i, j)
        for k in range(1, n+1):
            i_j_k = math.gcd(i_j, k)
            max_codiv.append(i_j_k)
print(sum(max_codiv))

Fixed submission:
# 最大公約数を格納するリストを初期化
max_codiv = []
 
# 繰り返す数を入力
n = int(input())
 
import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
	for j in range(1, n+1):
		i_j = math.gcd(i, j)
		for k in range(1, n+1):
			i_j_k = math.gcd(i_j, k)
			max_codiv.append(i_j_k)
print(sum(max_codiv))

Buggy python submission (verdict: Time Limit Exceeded):
# 最大公約数を格納するリストを初期化
max_codiv = []

# 繰り返す数を入力
n = int(input())

import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            i_j = math.gcd(i, j)
            i_j_k = math.gcd(i_j, k)
            max_codiv.append(i_j_k)
print(sum(max_codiv))

Fixed submission:
# 最大公約数を格納するリストを初期化
max_codiv = []
 
# 繰り返す数を入力
n = int(input())
 
import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
	for j in range(1, n+1):
		i_j = math.gcd(i, j)
		for k in range(1, n+1):
			i_j_k = math.gcd(i_j, k)
			max_codiv.append(i_j_k)
print(sum(max_codiv))
Buggy python submission (verdict: Runtime Error):
K, N = map(int, input().split())
A = [int(i) for i in input().split()]

max_dist = A_dist[0] = A[0] + (K - A[-1])
for i in range(1, N):
    if A[i] - A[i-1] > min_dist:
        max_dist = A[i] - A[i-1]

print(K - max_dist)

Fixed submission:
K, N = map(int, input().split())
A = [int(i) for i in input().split()]

A_dist = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        A_dist[0] = A[0] + (K - A[-1])
    else:
        A_dist[i] = A[i] - A[i-1]

print(K - max(A_dist))
Buggy python submission (verdict: Runtime Error):
S = input()
S_rvs = S[::-1]
N = len(S)

if N >= 7 and S == S_rvs and S[:(N-1)/2] == S_rvs[(N+3)/2:] and S[(N+3)/2:] == S_rvs[:(N-1)/2]:
    print("Yes")
else:
    print("No")

Fixed submission:
S = input()
S_rvs = S[::-1]
N = len(S)
left = int((N-1)/2)
right = int((N+3)/2-1)

if S == S_rvs and S[:left] == S_rvs[right:] and S[right:] == S_rvs[:left]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np

S = input()
Q = int(input())
q = np.array([[i for i in input().split()] for j in range(Q)])

for i in range(Q):
    if q[i,0] == "1":
        S = S[::-1]
    elif q[i,0] == "2":
        if q[i,1] == "1":
            S = q[i,2] + S
        else:
            S = S + q[i,2]
            
print(S)

Fixed submission:
S = input()
Q = int(input())
q = [[i for i in input().split()] for j in range(Q)]

f = ""
l = ""
count = 0
for i in range(Q):
    if q[i][0] == "1":
        count += 1
    elif q[i][0] == "2":
        if count % 2 == 0:
            if q[i][1] == "1":
                f = q[i][2] + f
            else:
                l = l + q[i][2]
        else:
            if q[i][1] == "1":
                l = l + q[i][2]
            else:
                f = q[i][2] + f
        
if count % 2 == 0:
    print(f+S+l)
else:
    print((f+S+l)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
q = [[i for i in input().split()] for j in range(Q)]

for i in range(Q):
    if q[i][0] == "1":
        S = S[::-1]
    elif q[i][0] == "2":
        if q[i][1] == "1":
            S = q[i][2] + S
        else:
            S = S + q[i][2]
            
print(S)

Fixed submission:
S = input()
Q = int(input())
q = [[i for i in input().split()] for j in range(Q)]

f = ""
l = ""
count = 0
for i in range(Q):
    if q[i][0] == "1":
        count += 1
    elif q[i][0] == "2":
        if count % 2 == 0:
            if q[i][1] == "1":
                f = q[i][2] + f
            else:
                l = l + q[i][2]
        else:
            if q[i][1] == "1":
                l = l + q[i][2]
            else:
                f = q[i][2] + f
        
if count % 2 == 0:
    print(f+S+l)
else:
    print((f+S+l)[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
P = np.array([int(i) for i in input().split()])

max_sum = 0
for i in range(N-K+1):
    max_sum = max(max_sum, np.sum(P[i:i+K]))
    
print((max_sum + K) / 2)

Fixed submission:
N, K = map(int, input().split())
P = [int(i) for i in input().split()]

E = [0 for i in range(N+1)]
for i in range(N):
    E[i+1] = E[i] + (P[i] + 1) / 2
    
ans = 0
for i in range(N-K+1):
    ans = max(ans, E[i+K] - E[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = [int(i) for i in input().split()]

max_sum = 0
for i in range(N-K+1):
    max_sum = max(max_sum, sum(P[i:i+K]))
    
print((max_sum + K) / 2)

Fixed submission:
N, K = map(int, input().split())
P = [int(i) for i in input().split()]

E = [0 for i in range(N+1)]
for i in range(N):
    E[i+1] = E[i] + (P[i] + 1) / 2
    
ans = 0
for i in range(N-K+1):
    ans = max(ans, E[i+K] - E[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(input().split())
if M == N:
    print("Yes")
else:
    print("No")

Fixed submission:
N, M = map(int, input().split())
if M == N:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
al = list("abcdefghijklmn")
C = input()
print(al[al.index(C)+1])

Fixed submission:
al = list("abcdefghijklmnopqrstuvwxyz")
C = input()
print(al[al.index(C)+1])
Buggy python submission (verdict: Runtime Error):
X = int(input())

def check(num):
    max_div = int(num**0.5)
    for div in range(2, max_div+1):
        if num % div == 0:
            return False
    else:
        return True

num = X
while True:
    if check(num):
    print(num)
    break
    
    num += 1

Fixed submission:
X = int(input())

def check(num):
    max_div = int(num**0.5)
    for div in range(2, max_div+1):
        if num % div == 0:
            return False
    else:
        return True

num = X
while True:
    if check(num):
        print(num)
        break
    
    num += 1

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

X = int(input())
nums = deque([i for i in range(3, 10**5+10, 2)])

prime = 2
while prime < X:
    prime = nums.popleft()
    nums = deque([i for i in nums if i % prime != 0])
print(prime)

Fixed submission:
X = int(input())

def check(num):
    max_div = int(num**0.5)
    for div in range(2, max_div+1):
        if num % div == 0:
            return False
    else:
        return True

num = X
while True:
    if check(num):
        print(num)
        break
    
    num += 1
Buggy python submission (verdict: Runtime Error):
import sys

N = int(input())
G = [[] for i in range(N)]
temp = sys.stdin.readlines()
for line in temp:
    u, v, d = map(int, line.split())
    G[u-1].append([v-1, d])
    G[v-1].append([u-1, d])
    
def dfs(v, G, cur=0):
    # 色をメモ
    color[v] = cur
        
    # 隣接するノードの色を調べる
    for next_v in G[v]:
        # 隣接ノードが探索済みなら、色が正しいか確かめる
        if color[next_v[0]] != -1:
            continue
            
        # 隣接ノードが未探索なら、正しい色に更新して再帰的に探索
        if next_v[1] % 2 == 0:
            dfs(next_v[0], G, cur)
        else:
            dfs(next_v[0], G, 1-cur)

color = [-1 for i in range(N)]
dfs(0, G)
for i in range(N):
    print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for i in range(N)]
temp = sys.stdin.readlines()
for line in temp:
    u, v, d = map(int, line.split())
    G[u-1].append([v-1, d])
    G[v-1].append([u-1, d])
    
def dfs(v, G, cur=0):
    # 色をメモ
    color[v] = cur
        
    # 隣接するノードの色を調べる
    for next_v in G[v]:
        # 隣接ノードが探索済みなら、色が正しいか確かめる
        if color[next_v[0]] != -1:
            continue
            
        # 隣接ノードが未探索なら、正しい色に更新して再帰的に探索
        if next_v[1] % 2 == 0:
            dfs(next_v[0], G, cur)
        else:
            dfs(next_v[0], G, 1-cur)

color = [-1 for i in range(N)]
dfs(0, G)
for i in range(N):
    print(color[i])
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())
    print(S[l-1:r].count("AC"))

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

ls = [0 for i in range(len(S)+1)]
for i in range(1, len(S)):
    if S[i-1] == "A" and S[i] == "C":
        ls[i+1] = ls[i] + 1
    else:
        ls[i+1] = ls[i]

for i in range(Q):
    l, r = map(int, input().split())
    print(ls[r]-ls[l])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

# 入力
N = int(input())
H = [int(i) for i in input().split()]

# メモ用のDPテーブルを生成
dp = [float("inf") for i in range(N)]

# 足場iにたどり着く最初コストを返す
def rec(i):
    # ベースケースをセット
    if i == 0:
        return 0
    
    # メモをチェック
    if dp[i] < float("inf"):
        return dp[i]
    
    # i-1から遷移する場合
    cost = rec(i-1) + abs(H[i] - H[i-1])
    # i-2から遷移する場合
    if i > 1:
        cost = min(cost, rec(i-2) + abs(H[i] - H[i-2]))
    
    # 結果をメモしてから返す
    dp[i] = cost
    return cost

print(rec(N-1))

Fixed submission:
# 最小値に置き換える関数
def chmin(a, b):
    if a > b:
        a = b
        return True
    
    return False

# 入力
N = int(input())
H = [int(i) for i in input().split()]

# dpテーブルの生成
dp = [float("inf") for i in range(N)]
# 初期条件のセット(足場1)
dp[0] = 0

# N番目の足場までのループ
# i = 1のときはi-2がないことに注意
for i in range(N):
    # ノードi-1からの遷移を計算
    dp[i] = min(dp[i], dp[i-1]+abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(H[i] - H[i-2]))

# dpテーブルの末尾が答え
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# 入力
N = int(input())
H = [int(i) for i in input().split()]

# メモ用のDPテーブルを生成
dp = [float("inf") for i in range(N)]

# 足場iにたどり着く最初コストを返す
def rec(i):
    # ベースケースをセット
    if i == 0:
        return 0
    
    # メモをチェック
    if dp[i] < float("inf"):
        return dp[i]
    
    # i-1から遷移する場合
    cost = rec(i-1) + abs(H[i] - H[i-1])
    # i-2から遷移する場合
    if i > 1:
        cost = min(cost, rec(i-2) + abs(H[i] - H[i-2]))
    
    # 結果をメモしてから返す
    dp[i] = cost
    return cost

print(rec(N-1))

Fixed submission:
# 最小値に置き換える関数
def chmin(a, b):
    if a > b:
        a = b
        return True
    
    return False

# 入力
N = int(input())
H = [int(i) for i in input().split()]

# dpテーブルの生成
dp = [float("inf") for i in range(N)]
# 初期条件のセット(足場1)
dp[0] = 0

# N番目の足場までのループ
# i = 1のときはi-2がないことに注意
for i in range(N):
    # ノードi-1からの遷移を計算
    dp[i] = min(dp[i], dp[i-1]+abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(H[i] - H[i-2]))

# dpテーブルの末尾が答え
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# 足場iにたどり着く最初コストを返す
def rec(i):
    # ベースケースをセット
    if i == 0:
        return 0
    
    # i-1から遷移する場合
    cost = rec(i-1) + abs(H[i] - H[i-1])
    
    if i > 1:
        # i-2から遷移する場合
        cost = min(cost, rec(i-2) + abs(H[i] - H[i-2]))
    
    return cost

# 入力
N = int(input())
H = [int(i) for i in input().split()]

print(rec(N-1))

Fixed submission:
# 最小値に置き換える関数
def chmin(a, b):
    if a > b:
        a = b
        return True
    
    return False

# 入力
N = int(input())
H = [int(i) for i in input().split()]

# dpテーブルの生成
dp = [float("inf") for i in range(N)]
# 初期条件のセット(足場1)
dp[0] = 0

# N番目の足場までのループ
# i = 1のときはi-2がないことに注意
for i in range(N):
    # ノードi-1からの遷移を計算
    dp[i] = min(dp[i], dp[i-1]+abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(H[i] - H[i-2]))

# dpテーブルの末尾が答え
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
V = np.array([[int(i) for i in input().split()] for j in range(N)])

dp = np.zeros((N, 3), int)
dp[0] = V[0]
for i in range(1, N):
    dp[i,0] = max(dp[i-1,np.array([1,2])]+V[i,0])
    dp[i,1] = max(dp[i-1,np.array([0,2])]+V[i,1])
    dp[i,2] = max(dp[i-1,np.array([0,1])]+V[i,2])

print(dp[N-1].max())

Fixed submission:
import numpy as np

# 入力
N = int(input())
a = np.array([[int(i) for i in input().split()] for j in range(N)]).T

# a(0行), b(1行), c(2行)の添え字付きDPテーブルを生成
dp = np.zeros(3*(N+1), dtype=int).reshape(3, (N+1))

# 0日目(0)からN-1日目(N-1)までループ処理
for i in range(N):    # 参照する前日(i)
    for j in [0, 1, 2]:    # 前日(i)のアクティビティ
        for k in [0, 1, 2]:    # 当日(i+1)のアクティビティ
            if j != k:    # 前日のアクティビティではいけない
                dp[k, i+1] = max(dp[k, i+1], dp[j, i] + a[j, i])
                
# N日目の処理
ans = 0
for j in [0, 1, 2]:
    ans = max(ans, dp[j, N])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# 入力
N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    for sum_w in range(W+1):    # 遷移の行き先の総重量
        # i番目の荷物を選ぶ場合
        if sum_w - wv[i][0] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-wv[i][0]]+wv[i][1])
        
        # i番目の荷物を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])

Fixed submission:
import numpy as np

# 入力
N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    dp[i+1][:wv[i-1][0]] = dp[i][:wv[i-1][0]]
    dp[i+1][wv[i-1][0]:] = np.maximum(dp[i][wv[i-1][0]:], dp[i][:(W+1)-wv[i-1][0]] + wv[i-1][1])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# 入力
N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for j in range(N)]

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    for sum_w in range(W+1):    # 遷移の行き先の総重量
        # i番目の荷物を選ぶ場合
        if sum_w - wv[i][0] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-wv[i][0]]+wv[i][1])
        
        # i番目の荷物を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])

Fixed submission:
import numpy as np

# 入力
N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    dp[i+1][:wv[i-1][0]] = dp[i][:wv[i-1][0]]
    dp[i+1][wv[i-1][0]:] = np.maximum(dp[i][wv[i-1][0]:], dp[i][:(W+1)-wv[i-1][0]] + wv[i-1][1])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
    
def func():
    for i in range(1, K+1):
        for j in range(N):
            if i - A[j] >= 0:
                dp[i] |= ~dp[i - A[j]]
                
dp = [0 for i in range(K+1)]
func()
if dp[K]: print("First")
else: print("Second")

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

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

dp = [0 for i in range(K+1)]
for i in range(K+1):
    if not dp[i]:
        for j in range(N):
            if i + A[j] < K + 1:
                dp[i+A[j]] = 1

if dp[K]: print("First")
else: print("Second")