Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

s = []
for _ in range(N):
    s += [int(input())]

ans = 0
for i in range(2 ** N):
    tmp = 0
    for j in range(N):
        if (i >> j) & 1:
            tmp += s[j]
    if tmp%10 == 0:
        tmp = 0
    ans = max(ans, tmp)

print (ans)

Fixed submission:
#Nの最大値が100なのでbit-DPでは間に合わない

N = int(input())

s = []
total = 0
for _ in range(N):
    a = int(input())
    s += [a]
    total += a

s.sort()
if total % 10 != 0:
    print (total)
    exit()
else:
    for i in range(N):
        if s[i]%10 != 0:
            print (total - s[i])
            exit()
print (0)

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

s = []
for _ in range(N):
    s += [int(input())]

ans = 0
for i in range(2 ** N):
    tmp = 0
    for j in range(N):
        if (i >> j) & 1:
            tmp += s[j]
    if tmp%10 == 0:
        tmp = 0
    ans = max(ans, tmp)

print (ans)

Fixed submission:
#Nの最大値が100なのでbit-DPでは間に合わない

N = int(input())

s = []
total = 0
for _ in range(N):
    a = int(input())
    s += [a]
    total += a

s.sort()
if total % 10 != 0:
    print (total)
    exit()
else:
    for i in range(N):
        if s[i]%10 != 0:
            print (total - s[i])
            exit()
print (0)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N = int(input())
a = list(map(int, input().split()))

def check(k):
    heap = []
    for i in range(k):
        heapq.heappush(heap, -1 * a[i])

    tmp = 0
    for _ in range(N):
        tmp -= heapq.heappop(heap)

    heap = []
    for i in range(k, 3 * N):
        heapq.heappush(heap, a[i])

    for _ in range(N):
        tmp -= heapq.heappop(heap)
    # print (tmp)
    return tmp

ans = -1 * 10 ** 20
for i in range(N, 2*N+1):
    ans = max(ans, check(i))
print (ans)

Fixed submission:
import heapq
N = int(input())
a = list(map(int, input().split()))

heap_left = []
left = 0
for i in range(N):
    left += a[i]
    heapq.heappush(heap_left, a[i])

lst_left = [left]
for i in range(N, 2 * N):
    tmp = heapq.heappushpop(heap_left, a[i])
    left = left - tmp + a[i]
    lst_left += [left]

heap_right = []
right = 0
for i in range(2 * N, 3 * N):
    right += a[i]
    heapq.heappush(heap_right, -1 * a[i])

lst_right = [right]
for i in range(2 * N -1, N-1, -1):
    tmp = heapq.heappushpop(heap_right, -1 * a[i])
    right = right - (-1 * tmp) + a[i]
    lst_right += [right]

# print (lst_left)
# print (lst_right)
ans = -1 * 10 ** 20
for i in range(N+1):
    # print (lst_left[i], lst_right[-(i+1)])
    ans = max(ans, lst_left[i]-lst_right[-(i+1)])

print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N = int(input())
a = list(map(int, input().split()))

def check(k):
    heap = []
    for i in range(k):
        heapq.heappush(heap, -1 * a[i])

    tmp = 0
    for _ in range(N):
        tmp -= heapq.heappop(heap)

    heap = []
    for i in range(k, 3 * N):
        heapq.heappush(heap, a[i])

    for _ in range(N):
        tmp -= heapq.heappop(heap)
    # print (tmp)
    return tmp

ans = -1 * 10 ** 20
for i in range(N, 2*N+1):
    ans = max(ans, check(i))
print (ans)

Fixed submission:
import heapq
N = int(input())
a = list(map(int, input().split()))

heap_left = []
left = 0
for i in range(N):
    left += a[i]
    heapq.heappush(heap_left, a[i])

lst_left = [left]
for i in range(N, 2 * N):
    tmp = heapq.heappushpop(heap_left, a[i])
    left = left - tmp + a[i]
    lst_left += [left]

heap_right = []
right = 0
for i in range(2 * N, 3 * N):
    right += a[i]
    heapq.heappush(heap_right, -1 * a[i])

lst_right = [right]
for i in range(2 * N -1, N-1, -1):
    tmp = heapq.heappushpop(heap_right, -1 * a[i])
    right = right - (-1 * tmp) + a[i]
    lst_right += [right]

# print (lst_left)
# print (lst_right)
ans = -1 * 10 ** 20
for i in range(N+1):
    # print (lst_left[i], lst_right[-(i+1)])
    ans = max(ans, lst_left[i]-lst_right[-(i+1)])

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

H, W, K = map(int, input().split())

move = [(1, 0), (-1, 0), (0, 1), (0, -1)]

G = [list(input()) for _ in range(H)]
check = [[-1] * (W) for _ in range(H)]

que = deque()

flag = False
for h in range(H):
    for w in range(W):
        if G[h][w] == 'S':
            que.append((h, w))
            flag = True
            break
    if flag:
        break

x_min = h
x_max = h

y_min = w
y_max = w

check[h][w] = 0
while que:
    tmp = que.popleft()
    
    x = tmp[0]
    y = tmp[1]
    
    now_ = check[x][y]
    if now_ == K:
        continue

    for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        if G[nx][ny] == '#':
            continue
        if check[nx][ny] == -1:
            check[nx][ny] = now_ + 1
            que.append((nx, ny))
            
            x_min = min(x_min, nx)
            x_max = max(x_max, nx)

            y_min = min(y_min, ny)
            y_max = max(y_max, ny)

ans = 10 ** 18
ans = min(ans, (x_min + K - 1) // K + 1)
ans = min(ans, (H - x_max - 1 + K - 1) // K + 1)
ans = min(ans, (y_min + K - 1) // K + 1)
ans = min(ans, (W - y_max - 1 + K - 1) // K + 1)

print (ans)


Fixed submission:
from collections import deque

H, W, K = map(int, input().split())

move = [(1, 0), (-1, 0), (0, 1), (0, -1)]

G = [list(input()) for _ in range(H)]
check = [[-1] * (W) for _ in range(H)]

que = deque()

flag = False
for h in range(H):
    for w in range(W):
        if G[h][w] == 'S':
            que.append((h, w))
            flag = True
            break
    if flag:
        break

x_min = h
x_max = h

y_min = w
y_max = w

check[h][w] = 0
while que:
    tmp = que.popleft()
    
    x = tmp[0]
    y = tmp[1]
    
    now_ = check[x][y]
    if now_ == K:
        continue

    for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        if G[nx][ny] == '#':
            continue
        if check[nx][ny] == -1:
            check[nx][ny] = now_ + 1
            que.append((nx, ny))
            
            x_min = min(x_min, nx)
            x_max = max(x_max, nx)

            y_min = min(y_min, ny)
            y_max = max(y_max, ny)

ans = 10 ** 18
ans = min(ans, (x_min + K - 1) // K + 1)
ans = min(ans, (H - x_max - 1 + K - 1) // K + 1)
ans = min(ans, (y_min + K - 1) // K + 1)
ans = min(ans, (W - y_max - 1 + K - 1) // K + 1)

print (ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

G = [[] for _ in range(N + 1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)

check = [0] * (N + 1)
check[1] = 1
ans1 = [1]
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans1.append(next_)
           break

# print (ans1)

ans2 = []
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans2.append(next_)
           break

# print (ans2)

print (len(ans1) + len(ans2))
print (*ans2[::-1], *ans1)

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

G = [[] for _ in range(N + 1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)

check = [0] * (N + 1)
check[1] = 1
ans1 = [1]
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans1.append(next_)
           break

# print (ans1)

ans2 = []
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans2.append(next_)
           break

# print (ans2)

print (len(ans1) + len(ans2))
print (*ans2[::-1], end ='')
if len(ans1):
    print (' ', end = '')
else:
    print ()
print (*ans1)
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

# 前計算
for i in range(n - 1):
    x[i] = x[i + 1] - x[i]

for i in range(m - 1):
    y[i] = y[i + 1] - y[i]

N = [n - 1]
for i in range(n - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range(m - 3, 0, -2):
    M.append(M[-1] + i)
    # M.append((M[i] + (m - 1- 2 * (i + 1))) % MOD)

if N[0] % 2 == 0:
    N += N[::-1]
elif N[0] != 1:
    N += N[1::-1]

if M[0] % 2 == 0:
    M += M[::-1]
elif M[0] != 1:
    M += M[1::-1]

# print (x)
# print (y)
# print (N)
# print (M)

if len(x) - 1 > len(N):
    while True:
        pass

if len(y) - 1 > len(M):
    while True:
        pass


X_sum = 0
for i in range(n - 1):
    X_sum += x[i] * N[i]
    X_sum %= MOD

Y_sum = 0
for i in range(m - 1):
    Y_sum += y[i] * M[i]
    Y_sum %= MOD

print ((X_sum * Y_sum) % MOD)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

a, b, c = map(int, input().split())

if (b - a == c - b):
    print ('YES')
else:
    print ('NO')
Buggy python submission (verdict: Runtime Error):
x = int(input())
ans = (x//11) * 2
if x%11 <= 6:
    ans += 1
elif x% == 0:
    ans = ans
else:
    ans += 2

print (ans)


Fixed submission:
x = int(input())
ans = (x//11) * 2
if x%11 == 0:
    ans = ans
elif x%11 <= 6:
    ans += 1
else:
    ans += 2

print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    import sys
    sys.setrecursionlimit(10 ** 9)

    input = sys.stdin.readline

    N = int(input())

    G =[[] for _ in range(N + 1)] #iさんが勝った相手のリストを要素とするリスト
    for i in range(2, N + 1):
        a = int(input())
        G[a].append(i)

    # print (G)

    set_lst = [set() for _ in range(N + 1)] #使った数字を管理する
    tmp_lst = [0] * (N + 1) #次に使える最小を管理する

    # print (set_lst)
    # print (tmp_lst)

    def calc(x): #xからの移動先を検討
        tmp = 0 #何試合目に行うことができるか
        for next_ in G[x]:
            y = max(calc(next_), tmp_lst[x])
            while y in set_lst[x]: #既に使われていたとき、一つずつ更新する
                y += 1
            set_lst[x].add(y) #新しく使ったことを記録する
            if y == tmp_lst[x]:
                tmp_lst[x] = y + 1
            tmp = max(y, tmp)
        return tmp + 1

    ans = calc(1) - 1

    # print (set_lst)
    # print (tmp_lst)
    print (ans)

if __name__ == '__main__':
    main()

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

input = sys.stdin.readline

N = int(input())

G =[[] for _ in range(N + 1)] #iさんが勝った相手のリストを要素とするリスト
for i in range(2, N + 1):
    a = int(input())
    G[a].append(i)

# print (G)

def calc(x): #xからの移動先を検討
    tmp = 0
    lst = []
    for next_ in G[x]:
        y = calc(next_)
        lst.append(y)
    lst.sort()
    for i in lst:
        if tmp >= i:
            tmp += 1
        else: #tmp < i
            tmp = i
    return tmp + 1

ans = calc(1) - 1

print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

N = int(input())

G =[[] for _ in range(N + 1)] #iさんが勝った相手のリストを要素とするリスト
for i in range(2, N + 1):
    a = int(input())
    G[a].append(i)

# print (G)

set_lst = [set() for _ in range(N + 1)] #使った数字を管理する
tmp_lst = [0] * (N + 1) #次に使える最小を管理する

# print (set_lst)
# print (tmp_lst)

def calc(x): #xからの移動先を検討
    tmp = 0 #何試合目に行うことができるか
    for next_ in G[x]:
        y = max(calc(next_), tmp_lst[x])
        while y in set_lst[x]: #既に使われていたとき、一つずつ更新する
            y += 1
        set_lst[x].add(y) #新しく使ったことを記録する
        if y == tmp_lst[x]:
            tmp_lst[x] = y + 1
        tmp = max(y, tmp)
    return tmp + 1

ans = calc(1) - 1

# print (set_lst)
# print (tmp_lst)
print (ans)

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

input = sys.stdin.readline

N = int(input())

G =[[] for _ in range(N + 1)] #iさんが勝った相手のリストを要素とするリスト
for i in range(2, N + 1):
    a = int(input())
    G[a].append(i)

# print (G)

def calc(x): #xからの移動先を検討
    tmp = 0
    lst = []
    for next_ in G[x]:
        y = calc(next_)
        lst.append(y)
    lst.sort()
    for i in lst:
        if tmp >= i:
            tmp += 1
        else: #tmp < i
            tmp = i
    return tmp + 1

ans = calc(1) - 1

print (ans)
Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())

count = 0
for x in range(0,K):
    for y in range(0,K):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)

Fixed submission:
S = input().split(',')
print (S[0]+' '+S[1]+' '+S[2])
Buggy python submission (verdict: Time Limit Exceeded):
#入力
K, S = map(int, input().split())

count = 0
x = 0
while x <= K:
    y = 0
    while y <= K:
        a = S-x-y
        if a <= K and a >= 0:
            count += 1
        y += 1
    x += 1

print(count)

#↑TLE

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

count = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)

Buggy python submission (verdict: Time Limit Exceeded):
#入力
K, S = map(int, input().split())

count = 0
x = 0
while x <= K:
    y = 0
    while y <= K:
        if S-x-y <= K and S-x-y >= 0:
            count += 1
        y += 1
    x += 1

print(count)

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

count = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)
Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())

count = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)

Fixed submission:
sx, sy, tx, ty = map(int, input().split())

x = tx - sx
y = ty - sy

s = 'U'*y + 'R'*x +'U' + 'L'* (x+1) + 'D'*(y+1) + 'R'
s += 'R'*x + 'U'*y +'R' + 'D'* (y+1) + 'L'*(x+1) + 'U'
print(s)
Buggy python submission (verdict: Runtime Error):
import numpy as np
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')

Fixed submission:
import numpy as np
import sys
sys.setrecursionlimit(10 **9)
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, A = map(int, input().split())
x = list(map(int, input().split()))

X = max(x)
if X < A:
    X = A

def check(j, k, s):
    if dp[j][k][s] != -1:
        return dp[j][k][s]
    if j == 0 and k == 0 and s == 0:
        dp[j][k][s] = 1
        return 1
    if j >= 1 and s < x[j-1]:
        a = check(j-1, k ,s)
        dp[j][k][s] = a
        return a
    if j >= 1 and k >= 1 and s >= x[j-1]:
        a = check(j-1, k, s) + check(j-1, k-1, s-x[j-1])
        dp[j][k][s] = a
        return a
    dp[j][k][s] = 0
    return 0
        
dp = [[[-1] * (N*X+1) for _ in range(N+1)] for _ in range(N + 1)]
dp = np.array(dp)
# print (dp)
# for j in range(N+1):
#     for k in range(N+1):
#         for s in range(N*X + 1):
#             print (j, k, s)
#             dp[j][k][s] = check(j, k, s)

ans = 0
for k in range(1, N+1):
    ans += check(N, k, k * A)
    # ans += dp[N][k][k * A]

print (ans)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

ans = X * min(K, N) + Y * max(N-K, 0)

print (ans)
Buggy python submission (verdict: Runtime Error):
#座標平面に落とし込んで再帰関数で無理やり計算
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5)
N, X = map(int, input().split())
if 2 * X > N: #対称性
    X = N - X

#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
    tmp = [-1]
    for j in range(N+1):
        if i <= j:
            tmp.append(0) #到達していないマス
        else:
            tmp.append(-1) #壁(範囲外)
    tmp.append(-1)
    tmp.reverse()
    dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))


#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
    if x == X and y == 1 and dp[x][y] == 1: #一周回ってもとの座標に戻ってきた時
        # print ('D')
        return total
    if m == 0: #右に動く時
        tmp = 0
        while dp[x-1][y+1] == 0: #右に進める時
            dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
            tmp += 1
            x -= 1
            y += 1
        if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
            # print ('1-B')
            return moving(x, y, total + tmp, 1)
        if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
            tmp += 1
            # print ('1-C')
            return moving(x-1, y+1, total + tmp, 2)
    
    if m == 1: #左下へ動く時
        tmp = 0
        while dp[x+1][y] == 0: #左下に進める時
            dp[x+1][y] = 1
            tmp += 1
            x += 1
        if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
            # print ('2-C')
            return moving(x, y, total + tmp, 2)
        if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
            tmp += 1
            # print ('2-C')
            return moving(x+1, y, total + tmp, 2)
    
    if m == 2: #左上に動く時
        tmp = 0
        while dp[x][y-1] == 0: #左上に進める時
            dp[x][y-1] = 1
            tmp += 1
            y -= 1
        if dp[x][y-1] == -1: #左上が壁の時-->右に進む
            # print ('3-A')
            return moving(x, y, total + tmp, 0)
        if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
            tmp += 1
            # print ('3-B')
            return moving(x, y-1, total + tmp, 1)

X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp))

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    ans += L[2 * i]

print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import unittest
import random

T = 26


def solve(d, c, s):
    best = [0] * d
    last = [-1]*T

    for i in range(d):
        max_v = -float('inf')
        for j in range(T):
            v = s[i][j] + c[j] * (i - last[j])
            if max_v < v:
                max_v = v
                best[i] = j
        last[best[i]] = i

    score = get_score(d, c, s, best)
    for i in range(1900):
        a = random.randint(0, d-1)
        b = random.randint(0, T-1)
        old = best[a]
        best[a] = b
        t_score = get_score(d, c, s, best)
        if t_score > score:
            score = t_score
        else:
            best[a] = old
    return best


def get_score(d, c, s, t):
    last = [-1]*T
    total = 0
    for i in range(d):
        total += s[i][t[i]]
        last[t[i]] = i
        for j in range(T):
            total -= c[j] * (i - last[j])
    return total


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    t = solve(d, c, s)
    print(get_score(d, c, s, t), file=sys.stderr)
    for i in range(d):
        print(t[i]+1)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_score(self):
        pass


Fixed submission:
def solve(d, c, s):
    return [1]*d


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    answer = solve(d, c, s)
    print(*answer, sep='\n')


if __name__ == "__main__":
    main()

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


def solve(d, c, s):
    answer = [0] * d
    best = [0] * d
    best_score = 0
    for i in range(d):
        for j in range(T):
            answer[i] = j
            score = get_score(d, c, s, answer)
            if score > best_score:
                best[i] = answer[i]
                best_score = score
        answer[i] = best[i]
    return best


def get_score(d, c, s, t):
    last = [-1]*T
    total = 0
    for i in range(d):
        total += s[i][t[i]]
        last[t[i]] = i
        for j in range(T):
            total -= c[j] * (i - last[j])
    return max(10**6+total, 0)


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    t = solve(d, c, s)
    print(get_score(d, c, s, t), file=sys.stderr)
    for i in range(d):
        print(t[i]+1)


if __name__ == "__main__":
    main()


Fixed submission:
def solve(d, c, s):
    return [1]*d


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    answer = solve(d, c, s)
    print(*answer, sep='\n')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0
for p in itertools.product(range(1, m + 1), repeat=n):
    if any(p[i] > p[i + 1] for i in range(n - 1)):
        continue
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
print(max_score)


Fixed submission:
import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0

p = [1] * n
cur = n-1
while cur >= 0:
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
    updated = False
    for i in range(n - 1, -1, -1):
        if p[i] != m:
            p[i] += 1
            for j in range(i + 1, n):
                p[j] = p[i]
            updated = True
            break
    if not updated:
        break

print(max_score)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0
for p in itertools.product(range(1, m + 1), repeat=n):
    if any(p[i] > p[i + 1] for i in range(n - 1)):
        continue
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
print(max_score)


Fixed submission:
import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0

p = [1] * n
cur = n-1
while cur >= 0:
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
    updated = False
    for i in range(n - 1, -1, -1):
        if p[i] != m:
            p[i] += 1
            for j in range(i + 1, n):
                p[j] = p[i]
            updated = True
            break
    if not updated:
        break

print(max_score)