Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02787 (python)

Fixed submission:
from sys import stdin
from sys import  setrecursionlimit
setrecursionlimit(10000)

[H, N] = [int(x) for x in stdin.readline().rstrip().split()]
As = []
Bs=[]
for i in range(N):
    [A, B] = [int(x) for x in stdin.readline().rstrip().split()]
    As.append(A)
    Bs.append(B)

INF = 10**10
dp_map = [[INF]*(H+1) for _ in range(N+1)]

#dp_map[i][j]: i番目の魔法までを使って、最低でもjのダメージを与える時に必要なMP
dp_map[0][0]  = 0
for i in range(N):
    for j in range(H+1):
        if j<As[i]:
            dp_map[i+1][j] = min(dp_map[i+1][0]+Bs[i],dp_map[i][j])
        else:
            dp_map[i+1][j] = min(dp_map[i+1][j-As[i]]+Bs[i] ,dp_map[i][j])

print(dp_map[N][H])

Buggy submission (verdict: Runtime Error):
from sys import stdin
from sys import  setrecursionlimit
setrecursionlimit(3000)

[H, N] = [int(x) for x in stdin.readline().rstrip().split()]
As = []
Bs=[]
for i in range(N):
    [A, B] = [int(x) for x in stdin.readline().rstrip().split()]
    As.append(A)
    Bs.append(B)

#dp_map = []
#for i in range(N+1):
#    temp_arr = [-1 for _ in range(H+1)]
#    dp_map.append(temp_arr)
dp_map = [[-1]*(H+1) for _ in range(N+1)]
#dp_map = [[-1]*(H+1)]*(N+1)
#print(len(dp_map))
#print(len(dp_map[0]))

def DP(i, j):
    if j<=0:
        return 0
    if dp_map[i][j]!=-1:
        return dp_map[i][j]
    
    if i==1:
        dp_map[i][j] = DP(i,j-As[i-1])+Bs[i-1]
        return dp_map[i][j]

    dp_map[i][j] = min(DP(i-1,j),DP(i,j-As[i-1])+Bs[i-1])
    return dp_map[i][j]

print(DP(N,H))

Buggy submission (verdict: Runtime Error):
from sys import stdin

[H, N] = [int(x) for x in stdin.readline().rstrip().split()]
As = []
Bs=[]
for i in range(N):
    [A, B] = [int(x) for x in stdin.readline().rstrip().split()]
    As.append(A)
    Bs.append(B)

dp_map = []
for i in range(N+1):
    temp_arr = [False for _ in range(H+1)]
    dp_map.append(temp_arr)

def DP(i, j):
    if j<=0:
        return 0
    if dp_map[i][j]!=False:
        return dp_map[i][j]
    
    if i==1:
        dp_map[i][j] = DP(i,j-As[i-1])+Bs[i-1]
        return dp_map[i][j]

    dp_map[i][j] = min(DP(i-1,j),DP(i,j-As[i-1])+Bs[i-1])
    return dp_map[i][j]

print(DP(N,H))

Buggy submission (verdict: Runtime Error):
from sys import stdin

[H, N] = [int(x) for x in stdin.readline().rstrip().split()]
As = []
Bs = []

for i in range(N):
    [a, b] = [int(x) for x in stdin.readline().rstrip().split()]
    As.append(a)
    Bs.append(b)


map_list = []
for i in range(10001):
    map_list.append(-1)


def DP(h):
    if h<=0:
        return 0
    if map_list[h]>=0:
        return map_list[h]
    
    temp_array = []
    for i in range(N):
        temp_array.append(DP(h-As[i])+Bs[i])
    map_list[h] = min(temp_array)
    

    return map_list[h]

print(DP(H))
Problem p03501 (python)

Fixed submission:
def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    A = input_string[1]
    B = input_string[2]

    price1 = A*N
    price2 = B

    print(min(price1,price2))

main()

Buggy submission (verdict: Runtime Error):
def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    max_time = 0
    for i in range(N):
        data.append(list(map(int,input().split())))
        max_num = max(data[i])
        if max_num>max_time:
            max_time=max_num

    #data_np = np.array(data).reshape(N,3)
    #data_np = np.array(data)

    #max_time = int(max(data))
    #print("max",max_time)
    schedule = [[0]*C for i in range(max_time)]
    #schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            if start+j-1<0:continue
            schedule[start+j-1][channel] = 1

#    for c in range(C):
#        for t in range(max_time):
#            if t==0:continue
#            if schedule[t][c]==1 and schedule[t-1][c]==0:
#                schedule[t-1][c]=1

    #max_N =0
    #for t in range(max_time):
    #    sum_of_ch = sum(schedule[t])

    temp = list(map(sum,list(schedule)))
    max_N = int(max(temp))


    #    if sum_of_ch>max_N:
    #        max_N = int(sum_of_ch)
    print(max_N)







main()

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

def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    for i in range(N):
        data.append(list(map(int,input().split())))

    data_np = np.array(data).reshape(N,3)

    max_time = max(data_np[:,1])
    schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            schedule[start+j][channel] = 1

    for c in range(C):
        for t in range(max_time):
            if t==0:continue
            if schedule[t][c]==1 and schedule[t-1][c]==0:
                schedule[t-1][c]=1

    max_N =0
    for t in range(max_time):
        sum_of_ch = sum(schedule[t])

        if sum_of_ch>max_N:
            max_N = int(sum_of_ch)
    print(max_N)







main()

Buggy submission (verdict: Runtime Error):
def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    A = input_string[1]
    B = input_string[2]

    price1 = A*T
    price2 = B

    print(min(price1,price2))

main()
Problem p03504 (python)

Fixed submission:
def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    max_time = 0
    for i in range(N):
        data.append(list(map(int,input().split())))
        max_num = max(data[i])
        if max_num>max_time:
            max_time=max_num

    #data_np = np.array(data).reshape(N,3)
    #data_np = np.array(data)

    #max_time = int(max(data))
    #print("max",max_time)
    schedule = [[0]*C for i in range(max_time)]
    #schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            if start+j-1<0:continue
            schedule[start+j-1][channel] = 1

#    for c in range(C):
#        for t in range(max_time):
#            if t==0:continue
#            if schedule[t][c]==1 and schedule[t-1][c]==0:
#                schedule[t-1][c]=1

    #max_N =0
    #for t in range(max_time):
    #    sum_of_ch = sum(schedule[t])

    temp = list(map(sum,list(schedule)))
    max_N = int(max(temp))


    #    if sum_of_ch>max_N:
    #        max_N = int(sum_of_ch)
    print(max_N)







main()

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

def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    for i in range(N):
        data.append(list(map(int,input().split())))

    data_np = np.array(data).reshape(N,3)

    max_time = max(data_np[:,1])
    schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            schedule[start+j][channel] = 1

    for c in range(C):
        for t in range(N):
            if t==0:continue
            if schedule[t][c]==1 and schedule[t-1][c]==0:
                schedule[t-1][c]=1

    max_N =0
    for t in range(max_time):
        sum_of_ch = sum(schedule[t])

        if sum_of_ch>max_N:
            max_N = int(sum_of_ch)
    print(max_N)







main()
Problem p02586 (python)

Fixed submission:
import sys
import time
s1 = time.time()
*data, = map(int, sys.stdin.read().split()[::-1])

def inp():
    global data
    return data.pop()
R, C, k = inp(), inp(), inp()
grid = [[0] * C for _ in range(R)]

for _ in range(k):
    ri, ci, v = inp(), inp(), inp()
    grid[ri - 1][ci - 1] = v


dp = []
for _ in range(4):
    dp.append([[0] * (C + 1) for _ in range(R + 1)])

# print(time.time() - s1)
mx = 0
for row in range(1, R + 1):
    for col in range(1, C + 1):
        level = 0
        dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1])
        dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col])
        level = 1
        v = grid[row - 1][col - 1]
        while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1)
print(mx)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
*p, = map(int, input().split())
p = [v - 1 for v in p]
*c, = map(int, input().split())
minc = float('-inf')

ans = minc


def get_loop(i):
    pos = i
    cnt = 0
    cur_score = 0
    while cnt == 0 or pos != i:
        pos = p[pos]
        cur_score = cur_score + c[pos]
        cnt += 1
    return cnt, cur_score

# print(get_loop(2))

def solve(pos, k):
    score = minc
    cur_score = 0
    loop_length, loop_score = get_loop(pos)
    if k >= 2 * loop_length and loop_score > 0:
        # print("%s: %s // %s, %s, %s" % (i, k, loop_length, cur_score, max_loop_score))
        cur_score = loop_score * ((k - loop_length) // loop_length)
        score = max(cur_score, score)
        k = k % loop_length + loop_length
    else:
        k = min(k, 2 * loop_length)
    for _ in range(k):
        pos = p[pos]
        cur_score += c[pos]
        score = max(cur_score, score)
    # print("%s: %s" % (i, score))
    return score

for i in range(n):
    ans = max(ans, solve(i, k))
print(ans)
Problem p02536 (python)

Fixed submission:
from collections import deque
n,m=map(int,input().split())
road=[[] for i in range(n)]
flag=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)
count=0
for i in range(n):
    if flag[i]!=0:
        continue
    count+=1
    q=deque([i])
    while q:
        p=q.popleft()
        flag[p]=1
        for z in road[p]:
            if flag[z]==0:
                q.append(z)
print(count-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m=map(int,input().split())
road=[[] for i i range(n)]
flag=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)
count=0
for i in range(n):
    if flag[i]!=0:
        continue
    count+=1
    q=[k]
    while q:
        p=q.popleft()
        for z in road[p]:
            if flag[z]==0:
                q.append(z)
print(count-1)
Problem p02646 (python)

Fixed submission:
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
z=(v*t)
y=(w*t)
if z-y>=abs(b-a):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
z=(v*t)+a
y=(w*t)+b
if w>=v:
    print("NO")
    break
if z-y>=0:
    print("YES")
else:
    print("NO")
Problem p02741 (python)

Fixed submission:
n =int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n-1])

Buggy submission (verdict: Runtime Error):
n =int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n])
Problem p02742 (python)

Fixed submission:
a,b =map(int,input().split())
ss = a*b
hf =ss//2
if a>1 and b>1:
	print(ss-hf)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
h,w =map(int,input(),split())
ss = (h*(w+1)//2)
if h>1 and w>1:
  print(ss)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
h,w =map(int,input(),split())
ss = (h*(w+1)//2)
if h>1 and w>1:
	print(ss)
else:
	print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
h,w =map(int,input(),split())
ss = (h*(w+1)//2)
if h>1 and w>1:
	print(ss)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import floor,ceil
    h,w=map(int,input().split())
    if h == 1 or w == 1:
        print(1)
    else:
        m =ceil(w/2) * ceil(h/2) + floor(w/2) * floor(h/2)
        print(m)

Buggy submission (verdict: Runtime Error):
from math import ceil
h,w =map(int,input(),split())
ss = (ceil(h/2)*ceil(w/2))+(h//2*w//2)
if h>1 and w>1:
	print(ss)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
a,b =map(int,input(),split())
ss = (ceil(a/2)*ceil(b/2))+(a//2*b//2)
if a>1 and b>1:
	print(ss)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
a,b =map(int,input(),split())
ss = (ceil(a/2)*ceil(b/2))+(a//2*b//2)
if a>1 and b>1:
	print(ss-hf)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
from math import ceil
a,b =map(int,input(),split())
ss = ceil(a/2)*ceil(b/2)+a//2*b//2
if a>1 and b>1:
	print(ss-hf)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input(),split())
ss = a*b
hf =ss//2
if a>1 and b>1:
	print(ss-hf)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input(),split())
ss = a*b
hf =ss//2
print(ss-hf)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input(),split())
ss = (a*b)//2
print(ss)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input(),split())
ss = a*b
print(ss-10)
Problem p02554 (python)

Fixed submission:
def main():
  MOD = int(1e9 + 7)
  n = int(input())
  print((pow(10,n,MOD) - 2*pow(9 , n , MOD)%MOD + pow(8 , n , MOD) + MOD)%MOD)
 
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  MOD = int(1e9 + 7)
  n = int(input())
  print((pow(10,n,MOD) - 2*pow(9 , n , MOD)%MOD + pow(8 , n , MOD) + MOD)%MOD)

if __namme__ == "__main__":
  main()
Problem p02556 (python)

Fixed submission:
def main():
  n = int(input())
  a_li , b_li = [] , []
  for _ in range(n):
    x , y = map(int,input().split())
    a_li.append(x + y)
    b_li.append(x - y)
  print(max(max(a_li) - min(a_li), max(b_li) - min(b_li)))
 
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  n = int(input())
  a_li , b_li = [] , []
  for _ in range(n):
    x , y = int(input())
    a_li.append(x + y)
    b_li.append(x - y)
    print(max(max(a_li) - min(a_li), max(b_li) - min(b_li)))

if __name__ == "__main__":
  main()
Problem p02606 (python)

Fixed submission:
l,r,d = map(int,input().split())
print(r//d-(l-1)//d)

Buggy submission (verdict: Runtime Error):
l,r,d = map(int,input().split())
print(r//d-(l-1)//d))
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
one_num = x.count('1')

ans_reduce,ans_add = 0,0
for i in range(n):
    if(one_num>1):
        ans_reduce = (ans_reduce+pow(2,n-i-1,one_num-1)*(1 if x[i] == '1' else 0))%(one_num-1)
    ans_add = (ans_add+pow(2,n-i-1,one_num+1)*(1 if x[i] == '1' else 0))%(1+one_num)

for i in range(n):
    now_one = one_num + (-1 if x[i] == '1' else 1)
    if(now_one == 0):
        print(0)
        continue
    num = ((ans_reduce if x[i] == '1' else ans_add) + pow(2,n-i-1,now_one)*(-1 if x[i] == '1' else 1))%now_one
    ans = 1
    while(num!=0):
        ans += 1
        num = num % bin(num).count('1')
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
one_num = x.count('1')

ans_reduce,ans_add = 0,0
for i in range(n):
    if(one_num>1):
        ans_reduce = (ans_reduce+pow(2,n-i-1,one_num-1)*(1 if x[i] == '1' else 0))%(one_num-1)
    ans_add = (ans_add+pow(2,n-i-1,one_num+1)*(1 if x[i] == '1' else 0))%(1+one_num)

for i in range(n):
    now_one = one_num + (-1 if x[i] == '1' else 1)
    num = ((ans_reduce if x[i] == '1' else ans_add) + pow(2,n-i-1,now_one)*(-1 if x[i] == '1' else 1))%now_one
    ans = 1
    while(num!=0):
        ans += 1
        num = num % bin(num).count('1')
    print(ans)
Problem p02608 (python)

Fixed submission:
n = int(input())
a = [0]*n
s = int(n**(1/2))+1
for i in range(1, s):
    for j in range(1, s):
        for k in range(1, s):
            b = i*i+j*j+k*k+i*j+j*k+k*i-1
            if b < n:
                a[b] += 1
for i in range(n):
    print(a[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0 for _ in range(10000)]
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            b = i*i+j*j+k*k+i*j+j*k+k*i-1
            if b < 10000:
                a[b] += 1
for i in range(n):
    print(a[n])
Problem p02618 (python)

Fixed submission:
d = int(input())
c = {}
s = []
C = list(map(int, input().split()))
for i in range(26):
    c[i] = C[i]
for i in range(d):
    s.append(list(map(int, input().split())))

for i in range(d):
    a = -1
    b = 0
    for j in range(26):
        if b < s[i][j]:
            a = j
            b = s[i][j]
    print(a+1)

Buggy submission (verdict: Runtime Error):
d = int(input())
c = {}
s = []
C = list(map(int, input().split()))
for i in range(26):
    c[i] = C[i]
for i in range(d):
    s.append(list(map(int, input().split())))

t = 0
while t < 365:
    for i in range(26):
        if t < 365:
            t += 1
            a = -1
            b = 0
            for j in range(26):
                if b < s[t][j]:
                    a = j
                    b = s[t][j]
            print(a+1)
        else:
            break;
        if t < 365:
            t += 1
            print(26-i)
        else:
            break;
Problem p02756 (python)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s.popleft()
else:
    for i in range(len(s)):
        c += s.pop()
print(c)

Buggy submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(0, b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s[i]
else:
    for i in range(len(s)):
        c += s[-i-1]
print(c)
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    t, d = map(int, input().split())
    s.append(t)
    c.append(d)
a = -2
if m == 0:
    if n == 1:
        a = 0
    elif n == 2:
        a = 10
    else:
        a = 100
else:
    for i in range(m-1):
        for j in range(i+1, m):
            if s[i] == s[j]:
                if c[i] != c[j]:
                    a = -1
    if a == -2:
        if n == 1:
            a = c[0]
        if n == 2:
            for i in range(10, 100):
                b = 0
                for j in range(m):
                    if s[j] == 1:
                        if i//10 == c[j]:
                            b += 1
                    else:
                        if i%10 == c[j]:
                            b += 1
                if b == m:
                    a = i
                    break;
        if n == 3:
            for i in range(100, 1000):
                b = 0
                for j in range(m):
                    if s[j] == 1:
                        if i//100 == c[j]:
                            b += 1
                    elif s[j] == 2:
                        if (i//10)%10 == c[j]:
                            b += 1
                    else:
                        if i%10 == c[j]:
                            b += 1
                if b == m:
                    a = i
                    break;
    if a == -2:
        a = -1
print(a)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    t, d = map(int, input().split())
    s.append(t)
    c.append(d)
a = -2
for i in range(m-1):
    for j in range(i+1, m):
        if s[i] == s[j]:
            if c[i] != c[j]:
                a = -1
if a == -2:
    if n == 1:
        a = c[0]
    if n == 2:
        for i in range(10, 100):
            b = 0
            for j in range(m):
                if s[j] == 1:
                    if i//10 == c[j]:
                        b += 1
                else:
                    if i%10 == c[j]:
                        b += 1
            if b == m:
                a = i
                break;
    if n == 3:
        for i in range(100, 1000):
            b = 0
            for j in range(m):
                if s[j] == 1:
                    if i//100 == c[j]:
                        b += 1
                elif s[j] == 1:
                    if (i//10)//10 == c[j]:
                        b += 1
                else:
                    if i%10 == c[j]:
                        b += 1
            if b == m:
                a = i
                break;
if a == -2:
    a = -1
print(a)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = [[] for _ in range(n)]; b = [-1]*n; b[0] = 0
for i in range(n-1):
    u, v, w = map(int, input().split())
    a[u-1].append([v-1, w]); a[v-1].append([u-1, w])
def dfs(A, k):
    for i in A[k]:
        if b[i[0]] == -1:
            b[i[0]] = b[k]+i[1]
            dfs(A, i[0])
dfs(a, 0)
for i in b:
    print(0) if i%2 == 0 else print(1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [[] for i in range(n)]; b = [-1]*n; b[0] = 0
for i in range(n-1):
    u, v, w = map(int, input().split())
    a[u-1].append([v-1, w]); a[v-1].append([u-1, w])
def dfs(A, k):
    for i in A[k]:
        if b[i[0]] == -1:
            b[i[0]] = b[k]+i[1]
            dfs(A, i[0])
dfs(a, 0)
for i in b:
    print(0) if i%2 == 0 else print(1)
Problem p03061 (python)

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
M = []
maximum = 0
for n in range(N):
    L.append(gcd(A[n], L[-1]))
    R.append(gcd(A[-n-1], R[-1]))
R.reverse()
for n in range(N):
    M.append(gcd(L[n], R[n+1]))
for n in range(N):
    maximum = max(maximum, M[n])
print(maximum)

Buggy submission (verdict: Runtime Error):
from function import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
M = []
maximum = 0
for n in range(N):
    L.append(gcd(A[n], L[-1]))
    R.append(gcd(A[-n-1], R[-1]))
R.reverse()
for n in range(N):
    M.append(gcd(L[n], R[n+1]))
for n in range(N):
    maximum = max(maximum, M[n])
print(maximum)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
M = []
maximum = 0
for n in range(N):
    L.append(gcd(A[n], L[-1]))
    R.append(gcd(A[-n-1], R[-1]))
R.reverse()
for n in range(N):
    M.append(gcd(L[n], R[n+1]))
for n in range(N):
    maximum = max(maximum, M[n])
print(maximum)