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

Fixed submission:
n, k = map(int,input().split())
m = n - k + 1 
def nCr(l,r,mod):
    if (r<0 or r>l):
        return 0
    r = min(r,l-r)
    return g1[l] * g2[r] * g2[l-r] % mod
mod = 10**9 + 7
N = 10**5
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]
for i in range(2,N+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k-1,i-1,mod)%mod)

Buggy submission (verdict: Runtime Error):
n, k = map(int,input().split())
m = n - k + 1 
def nCr(l,r,mod):
    if (r<0 or r>l):
        return 0
    r = min(r,l-r)
    return g1[l] * g2[r] * g2[l-r] % mod
mod = 10**9 + 7
N = 10**4
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]
for i in range(2,m+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k-1,i-1,mod))

Buggy submission (verdict: Runtime Error):
n,k= map(int,input().split())
m = n - k +1 
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(1,k+1):
    print(cmb(m,i,mod)*nmb(k,i-1,mod))

Buggy submission (verdict: Runtime Error):
n,k= map(int,input().split())
m = n - k +1 
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
print(g1)

for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k,i-1,mod))

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
print(g1)
n,k= map(int,input().split())
m = n - k +1 
for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k,i-1,mod))
Problem p03011 (python)

Fixed submission:
p,q,r = map(int,input().split())
print(min(p+q, q+r, r+p))

Buggy submission (verdict: Runtime Error):
p,q,r = map(int,input().split)
print(min(p+q, q+r, r+p))
Problem p03013 (python)

Fixed submission:
n, m = map(int,input().split())
p = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(m):
    a[int(input())] = 1
for i in range(1,n+1):
    if a[i] == 1:
        p[i] = 0
    elif i == 1:
        p[i] = 1
    elif i == 2:
        p[i] = p[1] + 1
    else:
        p[i] = p[i-1] + p[i-2]
print(p[n] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = []
import sys
sys.setrecursionlimit(10000)
for i in range(m):
    a.append(int(input()))
memo = [0 for i in range(n)]
done = [0 for i in range(n)]
def p(i):
    if done[i-1] == 1:
        return memo[i-1]
    if i in a:
        return 0
    elif i == 1:
        return 1
    elif i == 2:
        return p(1) + 1
    else:
        done[i-1] = 1
        memo[i-1] = p(i-1) + p(i-2)
        return memo[i-1]
print(p(n) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
memo = [0 for i in range(n)]
done = [0 for i in range(n)]
def p(i):
    if done[i-1] == 1:
        return memo[i-1]
    if i in a:
        return 0
    elif i == 1:
        return 1
    elif i == 2:
        return p(1) + 1
    else:
        done[i-1] = 1
        memo[i-1] = p(i-1) + p(i-2)
        return memo[i-1]
print(p(n) % (10**9 + 7))
Problem p03286 (python)

Fixed submission:
n = int(input())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if ans != "":
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if n != 0
    print(ans)
else:
    print(0)
Problem p03329 (python)

Fixed submission:
n = int(input())
memo = [-1] * (n+1)
import sys
sys.setrecursionlimit(1000000)
def f(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6 = 1
    pow9 = 1
    res = min(res, f(n - 1) + 1)
    while pow6*6 <= n:
        pow6 *= 6
        res = min(res, f(n - pow6) + 1)
        
    while pow9*9 <= n:
        pow9 *= 9
        res = min(res, f(n - pow9) + 1)
        
    memo[n] = res
    return res
print(f(n))

Buggy submission (verdict: Runtime Error):
n = int(input())
memo = [-1] * (n+1)
import sys
sys.setrecursionlimit(10000)
def f(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6 = 1
    pow9 = 1
    res = min(res, f(n - 1) + 1)
    while pow6*6 <= n:
        pow6 *= 6
        res = min(res, f(n - pow6) + 1)
        
    while pow9*9 <= n:
        pow9 *= 9
        res = min(res, f(n - pow9) + 1)
        
    memo[n] = res
    return res
print(f(n))
Problem p03803 (python)

Fixed submission:
a, b = map(int, input().split())
if a == 1 and b!= 1:
    print("Alice")
elif b == 1 and a != 1:
    print("Bob")
elif a > b:
    print("Alice")
elif b > a:
    print("Bob")
else:
    print("Draw")

Buggy submission (verdict: Runtime Error):
n , m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
#i, j はBの左端
for i in range(n-m+1):
    ans = True
    for j in range(n-m+1):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == True:
    print("Yes")
else:
    print("No")
Problem p03804 (python)

Fixed submission:
n , m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
#i, j はBの左端
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == True:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n , m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
#i, j はBの左端
for i in range(n-m):
    ans = True
    for j in range(n-m):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

if ans == True:
    print("Yes")
else:
    print("No")
Problem p03805 (python)

Fixed submission:
n, m = map(int,input().split())
lis = [0 for i in range(m)]
for i in range(m):
    lis[i] = list(map(int,input().split()))
    
seen = []
count = 0
visited = [0 for i in range(n)]
def route(x=1):
    visited[x-1] = 1
    if [1]*n == visited:
        global count
        count +=1
        return
    for i in range(m):
        if lis[i][0] == x and visited[lis[i][1]-1] == 0:
            route(lis[i][1])
            visited[lis[i][1]-1] = 0
        elif lis[i][1] == x and visited[lis[i][0]-1] == 0:
            route(lis[i][0])
            visited[lis[i][0]-1] = 0
    return
            
        
route(1)
print(count)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
lis = [0 for i in range(m)]
for i in range(m):
    lis[i] = list(map(int,input().split()))
    
seen = []
count = 0
visited = [0 for i in range(m)]
r = 0
def route(x=1):
    for i in range(m):
        if lis[i][0] == x and visited[i] == 0:
            visited[i] = 1
            r += 1
            route(lis[i][1])
            visited[i] = 0
            r -= 1
        elif lis[i][1] == x and visited[i] == 0:
            visited[i] = 1
            r += 1
            route(lis[i][0])
            visited[i] = 0
            r -= 1
        if r == n-1:
            global count
            count += 1
            return
        
            
        
route(1)
print(count)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
lis = [0 for i in range(m)]
for i in range(m):
    lis[i] = list(map(int,input().split()))
    
seen = []
count = 0
def route(x=1):
    for i in range(m):
        if lis[i][0] == x and visited[i] == 0:
            visited[i] = 1
            route(lis[i][1])
            visited[i] = 0
        elif lis[i][1] == x and visited[i] == 0:
            visited[i] = 1
            route(lis[i][0])
            visited[i] = 0
        r = 0
        for j in visited:
            r += j
        if r == n-1:
            global count
            count += 1
            return
        
            
        
route(1)
print(count)
Problem p02881 (python)

Fixed submission:
def solve(N):
    ans = []
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            ans.append(i+N//i-2)
    return min(ans)

N = int(input())
ans = solve(N)
print(ans)

Buggy submission (verdict: Runtime Error):
def solve(N):
    ans = []
    for i in range(1, int(N**0.5)):
        if N % i == 0:
            ans.append(i+N//i-2)
    return min(ans)

N = int(input())
ans = solve(N)
print(ans)
Problem p02915 (python)

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

print(N ** 3)

Buggy submission (verdict: Runtime Error):
#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
for i in range(1, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]

print(sum(A))
Problem p02880 (python)

Fixed submission:
import sys
N = int(input())
for i in range(1, 10):
  if N / i == int(N / i):
    if N / i < 10:
      print("Yes")
      sys.exit()
print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(1, 10):
  if N / i == int(N / i):
    if N / i < 10:
      print("Yes")
      return
print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(1, 10):
  if N / i == N // i:
    if N / i < 10:
      print("Yes")
      return
print("No")
Problem p02891 (python)

Fixed submission:
import sys
s = input()
k = int(input())
ret = 0
t = 0
ss = []
ss.append(s[0])
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        ss[-1]+=s[i]
    else:
        ss.append(s[i])

for ss_ in ss[1:-1]:
    ret += len(ss_) // 2 * k

if len(ss) >= 3:
    if ss[0][0] != ss[-1][0]:
        ret += len(ss[0]) // 2 * k
        ret += len(ss[-1]) // 2 * k
    else:
        ret += (len(ss[-1]) + len(ss[0]))  // 2 * (k-1)
        ret += len(ss[0]) // 2
        ret += len(ss[-1]) // 2

if len(ss) == 1:
    ret += len(ss[0]) * k // 2

if len(ss) == 2:
    ret += len(ss[0]) * k // 2
    ret += len(ss[1]) * k // 2

print(ret)

Buggy submission (verdict: Runtime Error):
import sys
s = input()
k = int(input())
ret = 0
t = 0

s = s*k

for j in range(1, len(s)):
    for i in range(len(s)-j):
        for u in range(j):
            if s[i + u] != s[i + u + 1]:
                break
            if u == j-1:
                if j % 2==1:
                    t += 1
                else:
                    t -= 1


print(t)
Problem p02859 (python)

Fixed submission:
r=int(input())
print(r*r)

Buggy submission (verdict: Runtime Error):
r=list(map(int, input().split()))
print(r*r)
Problem p03317 (python)

Fixed submission:
import math

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


print(math.ceil((N-1)/(K-1)))

Buggy submission (verdict: Runtime Error):
import math

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

if(N!=K):
    print(math.ceil(N/(K-1)))
else if((N+1)/K==2):
    print(2)
else:
    print(1)
Problem p03326 (python)

Fixed submission:
import numpy as np

N,M=list(map(int, input().split()))
A=[]
ret=[]
T=[[1,1,1],[1,1,-1],[1,-1,1],[-1,1,1],[1,-1,-1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
for i in range(N):
    l=list(map(int, input().split()))
    l.append(0)
    A.append(l)

def Score(a):
    return abs(a[0])+abs(a[1])+abs(a[2])

for t in T:
    for a in A:
        a[3]=a[0]*t[0]+a[1]*t[1]+a[2]*t[2]
    A.sort(key=lambda x:x[3],reverse=True)
    score=0
    for _ in range(M):
        score+=A[_][3]
    ret.append(score)
ret.sort(reverse=True)
print(ret[0])

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

N,M=list(map(int, input().split()))
A=[]
ret=[]
T=[[1,1,1],[1,1,-1],[1,-1,1],[-1,1,1],[1,-1,-1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
for i in range(N):
    l=list(map(int, input().split()))
    l.append(0)
    A.append(l)

def Score(a):
    return abs(a[0])+abs(a[1])+abs(a[2])

for t in T:
    for a in A:
        a[3]=a[0]*t[0]+a[1]*t[1]+a[2]*t[2]
    A.sort(key=lambda x:x[3],reverse=True)
    score=0
    for _ in range(M):
        score+=A[_][3]
    ret.append(score)
ret.sort(reverse=True)
print(ret[0])
Problem p02984 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

c = 0
for i in range(n):
    c += a[i] * (-2 * (i%2) + 1)

sol = [c]

for i in range(1,n):
    c = c * (-1) + 2 * a[i-1]
    sol.append(c)
    
print(' '.join(map(str, sol)))

Buggy submission (verdict: Runtime Error):
from numpy.linalg import solve

n = int(input())
a = [int(x) for x in input().split()]

#left = [[1] * 3 for i in range(3)]
left = []
for i in range(n-1):
    temp = [0] * n
    temp[i] = 1
    temp[i+1] = 1
    left.append(temp)
else:
    temp = [0] * n
    temp[0] = 1
    temp[-1] = 1
    left.append(temp)

#print(left)

right = [x * 2 for x in a]
#print(right)

sol = [int(x) for x in solve(left, right)]
print(' '.join(map(str, sol)))
Problem p03075 (python)

Fixed submission:
#coding:utf-8

import sys

L = list(int(input()) for i in range(6))

for i in range(5):
        for j in range(5):
            if abs(L[i]-L[j]) > L[5]:
                print(":(")
                sys.exit()

print("Yay!")

Buggy submission (verdict: Runtime Error):
#coding:utf-8

import sys

L = list(int(input()) for i in range(6))

for i in range(5):
        for j in range(5):
            if abs(L[i]-L[j]) > L[6]:
                print(":(")
                sys.exit()

print("Yay!")
Problem p02984 (python)

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

result = [0] * N
for i in range(N):
    result[0] += a_list[i] * (1 if i % 2 == 0 else -1)

for i in range(1, N):
    result[i] = 2 * a_list[i-1] - result[i-1]

print(' '.join(map(str, result)))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy import sparse
from scipy.sparse.linalg import inv
N = int(input())
a_list = list(map(int, input().split()))


m = np.zeros((N, N))

for i in range(N):
    m[i, i] = 0.5
    if i+1 == N:
        m[i, 0] = 0.5
    else:
        m[i, i+1] = 0.5

m = sparse.csc_matrix(m)
im = sparse.linalg.inv(m)
print(' '.join(map(str, list(im.dot(np.array(a_list)).astype(int)))))

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_list = list(map(int, input().split()))

m = np.zeros((N, N))

for i in range(N):
    m[i, i] = 0.5
    if i+1 == N:
        m[i, 0] = 0.5
    else:
        m[i, i+1] = 0.5

inv = np.linalg.inv(m)
print(' '.join(map(str, list(np.dot(inv, np.array(a_list)).astype(int)))))
Problem p02990 (python)

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(K):
    ni = (cmb(K-1, i, mod)) * (cmb(N-K+1, i+1, mod))
    print(ni % mod)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))

def c(n, k):
    result = 1
    for i in range(k):
        result *= n - i
    for i in range(k):
        result /= i + 1
    return int(result)

denom = (10 ** 9 + 7)
total = 0
for i in range(K):
    ni = (c(K-1, i) % denom) * (c(N-K+1, i+1) % denom)
    print(ni % denom)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))

def c(n, k):
    result = 1
    for i in range(k):
        result *= n - i
    for i in range(k):
        result /= i + 1
    return int(result)

total = 0
for i in range(K):
    ni = c(K-1, i) * c(N-K+1, i+1)
    print(ni % (10 ** 9 + 7))
Problem p03038 (python)

Fixed submission:
N, M = list(map(int, input().split()))
a_list = sorted(list(map(int, input().split())))
b_c_list = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    b_c_list.append((b, c))
b_c_list = sorted(b_c_list, key=lambda x: x[1], reverse=True)

def b_c_gen():
    for b, c in b_c_list:
        for _ in range(b):
            yield c

total = 0
for i, c in enumerate(b_c_gen()):
    if i >= N:
        break
    if a_list[i] >= c:
        i -= 1
        break
    total += c
i += 1

if i < N:
    total += sum(a_list[i:])
print(total)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
a_list = sorted(list(map(int, input().split())))
b_c_list = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    b_c_list.append((b, c))
b_c_list = sorted(b_c_list, key=lambda x: x[1], reverse=True)

def b_c_gen():
    for b, c in b_c_list:
        for _ in range(b):
            yield c

total = 0
for i, c in enumerate(b_c_gen()):
    if a_list[i] >= c:
        i -= 1
        break
    total += c
i += 1

if i < N:
    total += sum(a_list[i:])
print(total)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
a_list = sorted(list(map(int, input().split())))
b_c_list = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    b_c_list.append((b, c))
b_c_list = sorted(b_c_list, key=lambda x: x[1], reverse=True)

def b_c_gen():
    for b, c in b_c_list:
        for _ in range(b):
            yield c

total = 0
for i, c in enumerate(b_c_gen()):
    if a_list[i] >= c:
        i -= 1
        break
    total += c
i += 1

total += sum(a_list[i:])
print(total)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
a_list = sorted(list(map(int, input().split())))
b_c_list = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    b_c_list.append((b, c))
b_c_list = sorted(b_c_list, key=lambda x: x[1], reverse=True)

def b_c_gen():
    for b, c in b_c_list:
        for _ in range(b):
            yield c

def a_gen():
    while True:
        yield a_list.pop(0)

total = 0
for a, c in zip(a_gen(), b_c_gen()):
    if a >= c:
        break
    total += c

a_list.append(a)

total += sum(a_list)
print(total)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
a_list = sorted(list(map(int, input().split())))
b_c_list = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    b_c_list.append((b, c))
b_c_list = sorted(b_c_list, key=lambda x: x[1], reverse=True)

def b_c_gen():
    for b, c in b_c_list:
        for _ in range(b):
            yield c

def a_gen():
    while True:
        yield a_list.pop(0)

total = 0
for a, c in zip(a_gen(), b_c_gen()):
    if a >= c:
        a_list.append(a)
        break
    total += c

total += sum(a_list)
print(total)
Problem p02881 (python)

Fixed submission:
import math

N = int(input())
sum = N - 1
b = int(math.sqrt(N))
for i in range(2, b+1):
    if(N%i==0):
        if((N//i+i-2)<=sum):
            sum = N//i+i-2

print(sum)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
sum = N - 1
b = int(math.sqrt(N))
for i in range(2, b+1):
    if(N%i==0):
        if((a/i+i-2)<=sum):
            sum = N/i+i-2

print(sum)
Problem p02897 (python)

Fixed submission:
N = int(input())
cnt = 0
for i in range(1,N+1):
  if (i%2 == 1) :
    cnt += 1
print(cnt/N)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [0 for _ in range(M)]
b = [0 for _ in range(M)]
c = []
for i in range(M):
  a[i], b[i] = map(int, input().split())
  c.append(list(map(int, input().split())))

set_check = set([i+1 for i in range(N)])

def findkey(step, set_in, sum):
  if step == M-1:
    if set_check.issubset(set_in):
      return sum
    else:
      return -1
  right = findkey(step+1, set_in, sum)
  left = findkey(step+1, set_in | set(c[step+1]), sum+a[step+1])
  if left == -1:
    return right
  if right == -1:
    return left
  return min(left, right)
print(findkey(-1, set([]), 0))
Problem p02959 (python)

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

MaxValue = 0
if N == 1:
  MaxValue = min(B[0], A[0]+A[1])
  print(MaxValue)
else:
  for i in range(N):
    if A[i] < B[i]:
      #MaxValue += A[i]
      if A[i+1] < B[i] - A[i]:
        MaxValue += A[i+1] + A[i]
        A[i+1] = 0
      else:
        temp = B[i] - A[i]
        MaxValue += B[i]
        A[i+1] -= temp
    else:
      MaxValue += B[i]
  print(MaxValue)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

MaxValue = 0
if N == 1:
  MaxValue = min(B[0], A[0]+A[1])
  print(MaxValue)
else:
  for i in range(N):
    if A[i] < B[i]:
      #MaxValue += A[i]
      if A[i+1] < B[i] - A[i]:
        MaxValue += A[i+i] + A[i]
        A[i+1] = 0
      else:
        temp = B[i] - A[i]
        MaxValue += B[i]
        A[i+1] -= temp
    else:
      MaxValue += B[i]
  print(MaxValue)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

MaxValue = 0
if N == 1:
  MaxValue = min(B[0], A[0]+A[1])
  print(MaxValue)
else:
  for i in range(N):
    if A[i] < B[i]:
      MaxValue += A[i]
      if A[i+1] < B[i] - A[i]:
        MaxValue += A[i+i]
        A[i+1] = 0
      else:
        temp = B[i] - A[i]
        MaxValue += temp
        A[i+1] -= temp
    else:
      MaxValue += B[i]
  print(MaxValue)
Problem p02915 (python)

Fixed submission:
n = int(input())
print(n**3)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i>0 and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]
        
print(ans)
Problem p02916 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i>0 and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]
        
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())

order = list(map(int, input().split()))
menu = {}
tmp = list(map(int, input().split()))
for i in range(n):
    menu[i] = tmp[i]
# print(menu)
add = {}
tmp = list(map(int, input().split()))
for i in range(n-1):
    add[i] = tmp[i]

result = 0

for i in range(len(order)):
    # print(order[i]-1, menu[order[i]-1])
    result += menu[order[i]-1]
    if i < len(order)-1:
        if order[i+1] - order[i] == 1:
            # print(add[i-1])
            result += add[i-1]

print(result)