Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from functools import reduce
import math

n = input()
a = map(int, input().split())

print(reduce(lambda x,y: math.gcd(x, y), a))


Fixed submission:
from functools import reduce

def gcd(x,y):
    
    return y if x % y == 0 else gcd(y, x % y)

n = input()
a = map(int, input().split())

print(reduce(gcd, a))
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split(' '))

posts = input().split('-')
if len(s) == 2 and a == len(post[0]) and b == len(post[1]) and s[0].isnumeric() and s[1].isnumeric():
    print("Yes")
else:
    print("No")

Fixed submission:
print(48 - int(input()))

Buggy python submission (verdict: Runtime Error):
print(48 - int(input())

Fixed submission:
print(48 - int(input()))
Buggy python submission (verdict: Runtime Error):
if "AC" in input():
    print("Yes")
else
    print("No")

Fixed submission:
if "AC" in input():
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = input()

a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for c in s:
    if c in a:
        a.remove(c)

print(a[0])

Fixed submission:
s = input()

a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for c in s:
    if c in a:
        a.remove(c)
if len(a) > 0:
    print(a[0])
else:
    print("None")
Buggy python submission (verdict: Runtime Error):
a,b = input().split(' ')

if a == "H":
    print(b)
else if b == "H":
    print(a)
else:
    print("H")

Fixed submission:
a,b = input().split(' ')
 
if a == "H":
    print(b)
elif b == "H":
    print(a)
else:
    print("H")

Buggy python submission (verdict: Runtime Error):
a,b = input().split()

if a == "H":
    print(b)
else if b == "H":
    print(a)
else:
    print("H")

Fixed submission:
a,b = input().split(' ')
 
if a == "H":
    print(b)
elif b == "H":
    print(a)
else:
    print("H")
Buggy python submission (verdict: Runtime Error):
print(input().replace(","," ")

Fixed submission:
print(input().replace(","," "))
Buggy python submission (verdict: Runtime Error):
import sys

N = int(input())

a = input()
b = input()

for i in range(N):
	if(a[0:N-i] == b[i:N]){
		print(N+i)
		sys.exit()
		
print(2 * N)

Fixed submission:
import sys

N = int(input())

a = input()
b = input()

for i in range(N):
	if a[i:N] == b[0:N-i]:
		print(N+i)
		sys.exit()
		
print(2 * N)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())

print(k * ((k-1) ** (n-1)))

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

if a == b == c:
  print(1)
elif a == b or b == c or c == a:
  print(2)
else:
  print(3)
Buggy python submission (verdict: Runtime Error):
import functools
import operator

dic = {-1: 0, 0: 1, 1:1}

def pat(n):
  if n not in dic:
    dic[n] = pat(n-1) + pat(n-2)
  return dic[n]


import sys
n, m = map(int, input().split())
a = sorted(list(set(map(int, sys.stdin.readlines()))))
m = len(a)

s = 0
e = n
xs = [0] * (m + 1)
for i, j in enumerate(a):
  xs[i] = pat(j - s - 1)
  s = j + 1
xs[m] = pat(n - s)
if 0 in xs:
  print(0)
else:
  result = functools.reduce(operator.mul, xs)
  print(result % 1000000007)


Fixed submission:
def fb(num):
    """num番目のフィボナッチ数を返す
    """
    a, b = 1, 0
    for _ in range(num):
        a, b = a + b, a
    return b

import functools
import operator

import sys
n, m = map(int, input().split())
a = sorted(list(set(map(int, sys.stdin.readlines()))))
m = len(a)

s = 0
e = n
xs = [0] * (m + 1)
for i, j in enumerate(a):
  xs[i] = fb(j - s)
  s = j + 1
xs[m] = fb(n - s + 1)
if 0 in xs:
  print(0)
else:
  result = functools.reduce(operator.mul, xs)
  print(result % 1000000007)

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

dic = {-1: 0, 0: 1, 1:1}

def pat(n):
  if n not in dic:
    dic[n] = pat(n-1) + pat(n-2)
  return dic[n]


import sys
n, m = map(int, input().split())
a = list(map(int, sys.stdin.readlines()))

s = 0
e = n
xs = [0] * (m + 1)
for i, j in enumerate(a):
  xs[i] = pat(j - s - 1)
  s = j + 1
xs[m] = pat(n - s)
if 0 in xs:
  print(0)
else:
  result = functools.reduce(operator.mul, xs)
  print(result % 1000000007)


Fixed submission:
def fb(num):
    """num番目のフィボナッチ数を返す
    """
    a, b = 1, 0
    for _ in range(num):
        a, b = a + b, a
    return b

import functools
import operator

import sys
n, m = map(int, input().split())
a = sorted(list(set(map(int, sys.stdin.readlines()))))
m = len(a)

s = 0
e = n
xs = [0] * (m + 1)
for i, j in enumerate(a):
  xs[i] = fb(j - s)
  s = j + 1
xs[m] = fb(n - s + 1)
if 0 in xs:
  print(0)
else:
  result = functools.reduce(operator.mul, xs)
  print(result % 1000000007)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_lis = list(map(int, input().split()))
B_lis = list(map(int, input().split()))

f = [(B_lis[_]/A_lis[_], A_lis[_], B_lis[_]) for _ in range(3)]

f.sort()
f.reverse()

rest = N
gain = 0

for j in range(3):
  if f[j][0] > 1.0:
    g = rest // f[j][1]
    rest -= g * f[j][1]
    gain += g * f[j][2]

print(gain+rest)

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

if K==1:
  print(0)
else:
  print(N-K)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
char in[120];
pair<pair<string, int>, int> p[110];

int main () {
  int N;
  cin >> N;
  for (int i = 0; i< N; i++) {
    int t;
    string tmp;
    cin >> tmp >> t;
    
    p[i]=make_pair(make_pair(tmp,-t),i);
  }  
  sort(p,p+N);
  for (int i = 0; i<N;i++) {
    cout << p[i].second+1 << endl;
  }
}

Fixed submission:
#from IPython import embed
N=int(input())
n = []

from collections import Counter

c = Counter()

for i in range(N):
    k = input().split()
    k[1] = int(k[1])
    k.append(i+1)
    n.append(k)
    c.update([k[0]])



n.sort()
#n = n[::-1]
prev = ""
l = []
cnt = 0
#print(c)
for a in n:
    #print(a)

    if c[a[0]] > 1:
        l.append(a[1:])
        #print(a[1:])
        cnt+=1
        #print(a[0])
        #embed()
        if cnt == c[a[0]]:
            l.sort()
            #print(l)
            for i in l[::-1]:
                print(i[1])
            cnt = 0
            l = []
    else:
        print(a[2])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    for i in range(1, 33):
        n = 2 ** i - a
        if n in c.keys():
            if a == n and c[a] > 1:
                c[a] -= 2
                res += 1
            elif a != n and c[a] > 0 and c[n] > 0:
                c[a] -= 1
                c[n] -= 1
                res += 1
    
print(res)
    



Fixed submission:
from collections import Counter

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

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    n = 2 ** a.bit_length() - a
    if n in c.keys():
        if a == n and c[a] > 1:
            c[a] -= 2
            res += 1
        elif a != n and c[a] > 0 and c[n] > 0:
            c[a] -= 1
            c[n] -= 1
            res += 1
    
print(res)

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

A.sort()
#print(a)
A = A[::-1]
res = 0
while len(A) >= 2:
    for a in A[1:]:
        if not (A[0] + a & (A[0] + a - 1)):
            res += 1
            A.remove(a)
            break
    A.pop(0)
            
print(res)
    



Fixed submission:
from collections import Counter

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

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    n = 2 ** a.bit_length() - a
    if n in c.keys():
        if a == n and c[a] > 1:
            c[a] -= 2
            res += 1
        elif a != n and c[a] > 0 and c[n] > 0:
            c[a] -= 1
            c[n] -= 1
            res += 1
    
print(res)
Buggy python submission (verdict: Runtime Error):
n=list(input())
f=0
for i in range(len(n)):
    if(n[i]==n[i+1]):
    	f=1
if(f==1):
	print("Bad")
else:
	print("Good")

Fixed submission:
n=list(input())
f=0
for i in range(len(n)-1):
    if(n[i]==n[i+1]):
        f=1
if(f==1):
    print("Bad")
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
import math

i = []
for l in range(5):
    i.append(int(input()))
m = -1
l = 0
for x in range(5):
    if m < (10 - i[x] % 10) and 10 - i[x] % 10 != 10:
        if x != 0:
            l += math.ceil(i[mx] / 10) * 10
        m = 10 - i[x] % 10
        mx = x
    else:
        l += math.ceil(i[x] / 10) * 10
l += i[mx]
print(l)


Fixed submission:
import math

i = []
for l in range(5):
    i.append(int(input()))
m = 0
l = 0
mx = -1
for x in range(5):
    if m < (10 - i[x] % 10) and 10 - i[x] % 10 != 10:
        if x != 0:
            l += math.ceil(i[mx] / 10) * 10
        m = 10 - i[x] % 10
        mx = x
    else:
        l += math.ceil(i[x] / 10) * 10
if mx != -1:
    l += i[mx]
print(l)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
L = [l for l in map(int, input().split())]

num = 0
dist = 0
while dist <= x:
  dist += L[num]
  num += 1
  
print(num)

Fixed submission:
n, x = map(int, input().split())
L = [l for l in map(int, input().split())]

dist = 0
num = 1

for (i, v) in enumerate(L):
  dist += v
  if dist <= x:
    num += 1
    continue
  else:
    break
    
print(num)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = [int(i) for i in input().split()]

gate = np.zeros(N+1)
for i in range(0, M):
    L, R = [int(j) for j in input().split()]
    gate[L-1] += 1
    gate[R] -=1

count = 0
for i in range(1, len(gate)):
    gate[i] = gate[i] + gate[i-1]

for i in range(0, M):
    if gate[i] == M:
        count += 1

print(count)

Fixed submission:
import numpy as np
N, M = [int(i) for i in input().split()]

gate = np.zeros(N+1)
for i in range(0, M):
    L, R = [int(j) for j in input().split()]
    gate[L-1] += 1
    gate[R] -=1

count = 0
for i in range(1, len(gate)):
    gate[i] = gate[i] + gate[i-1]
    if gate[i] == M:
        count += 1

if gate[0] == M:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
X = 0
for i in range(N):
    if(V[i]-C[i] > 0):
        X += V[i] - C[i]
print(int(X))

Fixed submission:
A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
X = 0
for i in range(N):
    if(V[i]-C[i] > 0):
        X += V[i] - C[i]
print(X)

Fixed submission:
A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
V=list(map(int, input().split()))
C= list(map(int, input().split()))
X = 0
for i in range(N):
  if(V[i]-C[i]>0):
    X += V[i] -C[i]
print(X)

Fixed submission:
A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)

Buggy python submission (verdict: Runtime Error):
A, B, T map(int, input().split()) 
t_max = int((T+0.5)/A)
bis = 0
for t in range(t_max):
  bis += B*(t+1)
print(bis)

Fixed submission:
A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)

Buggy python submission (verdict: Runtime Error):
A,B,T=map(int, input().split())
t_max = int((T+0.5)/(A))
for t in range(t_max):
	bis += B*(t+1)
print(bis)

Fixed submission:
A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)
Buggy python submission (verdict: Runtime Error):
N = int(input)
V=list(map(int, input().split()))
C=list(map(int, input().split()))

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

Fixed submission:
N = int(input())
V = list(map(int, input().split( )))
C = list(map(int, input().split( )))
X = 0
for i in range(N):
    if(V[i]-C[i]>0):
        X += V[i] - C[i]
print(X)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = []
for _ in range(M):
    A.append(int(input()))

num_goup = [1]
for s in range(1, N + 1):
    if s in A:
        num_goup.append(0)
        continue
    
    if s == 1:
        num_goup.append(1)
        continue
    
    if num_goup[-1] == 0:
        if num_goup[-2] == 0:
            num_goup.append(0)
            break
        else:
            num_goup.append(num_goup[-2])
    else:
        if num_goup[-2] == 0:
            num_goup.append(num_goup[-1])
        else:
            num_goup.append(num_goup[-1] + num_goup[-2])
    
print(num_goup[-1])

Fixed submission:
P, Q, R = list(map(int, input().split()))
print(min(P+Q, Q+R, R+P))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
s = input()
k = int(input())

selected = s[k]
print(''.join(['*' if l != selected else l for l in s ]))

Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
s = input()
k = int(input())

selected = s[k - 1]
print(''.join(['*' if l != selected else l for l in s ]))
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
cn = b//c + (-a//c) + 1
dn = b//d + (-a//d) + 1
cd = (c*d)//math.gcd(c, d)
cdn = b//cd + (-a//cd) + 1
print(b-a+1-(cn+dn-cdn))

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
cn = b//c + (-a//c) + 1
dn = b//d + (-a//d) + 1
cd = (c*d)//fractions.gcd(c, d)
cdn = b//cd + (-a//cd) + 1
print(b-a+1-(cn+dn-cdn))

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
cn = b//c + (-a//c) + 1
dn = b//d + (-a//d) + 1
cd = lcm(c, d)
cdn = b//cd + (-a//cd) + 1
#print(cn, dn, cdn)
print(b-a+1-(cn+dn-cdn))

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
cn = b//c + (-a//c) + 1
dn = b//d + (-a//d) + 1
cd = (c*d)//fractions.gcd(c, d)
cdn = b//cd + (-a//cd) + 1
print(b-a+1-(cn+dn-cdn))
Buggy python submission (verdict: Runtime Error):
X, A = map(int(input().split()))
if(X < A): print(0)
else: print(10)

Fixed submission:
X, A = map(int, input().split())
if(X < A): print(0)
else: print(10)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
maps = [-1 for i in range(n)]
maps[0] = 0
for i in range(n-1):
    a, b, c = map(int, input().split())
    l.append([a-1, b-1, c])

while l != []:
    x = l.pop(0)
    if(maps[x[0]] != -1):
        maps[x[1]] = (maps[x[0]]+x[2])%2
    elif(maps[x[1]] != -1):
        maps[x[0]] = (maps[x[1]]+x[2])%2
    else: l.append(x)
    #print(maps)
for i in maps:
    print(i)


Fixed submission:
from collections import deque
n = int(input())
l = []
ans = [-1 for i in range(n+1)]

adj = [[] for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    adj[a].append([b, c])
    adj[b].append([a, c])

deq = deque()
deq.appendleft(1)

while len(deq) > 0:
    v = deq.pop()
    for u, w in adj[v]:
        if ans[u] == -1:
            deq.appendleft(u)
        if ans[v] == -1 and ans[u] == -1:
            if w %2 == 0:
                ans[v] = 0
                ans[u] = 0
            else:
                ans[v] = 0
                ans[u] = 1
        elif ans[v] == 0:
            if w % 2 == 0:
                ans[u] = 0
            else:
                ans[u] = 1
        else:
            if w % 2 == 0:
                ans[u] = 1
            else:
                ans[u] = 0
        #print(ans)

if(n == 1): 
    print(0)
else:
    for i in range(1, n+1):
        print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if(i*j*k > K): break
         else: tot.append(a[i] + b[j] + c[k])
tot.sort()
for i in range(K):
   print(tot[-(i+1)])


Fixed submission:
X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if((i+1)*(j+1)*(k+1) <= K): tot.append(a[i] + b[j] + c[k])
         else: break
tot.sort(reverse = True)
for i in range(K):print(tot[i])

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         tot.append(a[i] + b[j] + c[k])
tot.sort()
for i in range(K):
   print(tot[-(i+1)])

Fixed submission:
X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if((i+1)*(j+1)*(k+1) <= K): tot.append(a[i] + b[j] + c[k])
         else: break
tot.sort(reverse = True)
for i in range(K):print(tot[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
s = input()
lis = []
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): lis.append(i)
n = len(lis)
for i in range(Q):
    cnt = 0
    in0, in1 = map(int, input().split())
    for j in lis:
        if((in0-1)<= j < (in1-1)): cnt += 1
    print(cnt)


Fixed submission:
N, Q = map(int, input().split())
s = input()
nlis = [0]
cnt = 0
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): 
        cnt += 1
    nlis.append(cnt)
#print(nlis)
for i in range(Q):
    in0, in1 = map(int, input().split())
    print(nlis[in1-1]-nlis[in0-1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
L = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A.sort(reverse = True)

dp = [0] + ([-1]*N)
for i in range(1, N+1):
    for a in A:
        if L[a] <= i:
            dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)
    print(dp)
print(dp[-1])

Fixed submission:
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
L = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A.sort(reverse = True)

dp = [0] + ([-1]*N)
for i in range(1, N+1):
    for a in A:
        if L[a] <= i:
            dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
if((N-1)//(K-1)>=2):print("YES")
else: print("NO")

Fixed submission:
N, K = map(int, input().split())
if(K == 1): print("YES")
else:
    if((N-1)//(K-1)>=2):print("YES")
    else: print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
flowers = list(map(int, input().split()))
flowers.append(max(flowers))
cnt = 0
for i in range(sum(flowers)):
    if(all([x<0 for x in flowers])): break
    print(flowers, i, cnt)
    flowers = list(map(lambda x: (x-1), flowers))
    for j in range(n):
        if(flowers[j] > 0 and flowers[j+1] <= 0): cnt+=1
print(i + cnt)

Fixed submission:
n = int(input())
flowers = list(map(int, input().split()))
flowers.append(0)
cnt = 0
if(all([x<=0 for x in flowers])): print(0)
else: 
    for i in range(sum(flowers)+1):
        #print(i)
        if(all([x<=0 for x in flowers])): break
        #print(flowers, i, cnt)
        for j in range(n-2):
            if(flowers[j] > 0 and flowers[j+1] <= 0 and any([x>0 for x in flowers[j+2:]])): cnt+=1
        flowers = list(map(lambda x: (x-1), flowers))
    print(i + cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
score = list(map(int, input().split()))
sum_score = sum(score)
target = list(map(int, input().split()))
sum_target = sum(target)
sub = list(map(lambda x: score[x] - target[x], range(n)))
cnt = sum(1 for x in sub if x < 0)
sub.sort()
sub.reverse()

sub_new = [0]
for i in range(n):
    sub_new.append(sub_new[i] + sub[i])

if(sum_score > sum_target):
    if(cnt > 0):
        a, b, ans = 0, 0, 1
        tmp = sub_new[1+a]
        while sum(1 for x in sub if x < 0) > 0:
            if(tmp + sub[-(b+1)] >= 0): 
                tmp += sub[-(b+1)]
                sub[-(b+1)] = 0
                b+=1
            else: 
                sub[-(b+1)] -= tmp
                a+=1
                tmp = sub_new[1+a]
                ans += 1
            #print(tmp, sub, ans)
        print(cnt + ans)
    else: print(0)
else:
    print(-1)

Fixed submission:
n = int(input())
score = list(map(int, input().split()))
target = list(map(int, input().split()))

sub = [score[i] - target[i] for i in range(n)]
ans = 0

if sum(score) < sum(target): ans = -1
else:
    minus = []
    plus = []
    for i in range(n):
        if(sub[i] < 0): minus.append(-sub[i])
        elif(sub[i] > 0): plus.append(sub[i])
    plus = sorted(plus, reverse = True)
    sum_minus = sum(minus)

    ans += len(minus)
    while sum_minus > 0:
        if sum_minus <= plus[0]:
            plus[0] = 0
            sum_minus = 0
        else:
            sum_minus -= plus.pop(0)
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
pos = 0
length = 0
tree=[]

def position(b,i,pos,posA, posB):
    print(posA, posB)
    if(posA == posB):
        for j in range(b-1-i):
            neia, neib = (tree[j+1]-tree[j], tree[b-i-1-j]-tree[b-i-2-j])
            print(neia, neib)
            if(neia > neib):
                posB = 0
                break
            elif(neib > neia):
                posA = 0
                break
    target = max(posA, posB)
    print(posA, posB)
    if(posA == target):
        pos = tree[0]
        del tree[0]
    else:
        pos = tree[b-i-1]
        del tree[b-i-1]
    return (pos, target)

for i in range(b):
    tree.append(int(input()))
for i in range(b):
    print(tree)
    if(pos > tree[b-i-1]):
        pos, target = position(b,i,pos,abs(tree[0]+a-pos),abs(tree[b-i-1]-pos))
    else:
        pos, target = position(b,i,pos,abs(tree[0]-pos),a-abs(tree[b-i-1]-pos))
    length += target
    print(i+1, "----", pos, target, length) 
print(length)

Fixed submission:
L, N = map(int, input().split())
X=[0]
sumL=[0]
sumR=[0]
for i in range(N):
    X.append(int(input()))
    sumL.append(sumL[-1]+X[-1])
for i in range(N):
    sumR.append(sumR[-1]+L-X[N-i])
sumR.append(0)
sumR.reverse()
#print(X)
#print("sumL",sumL)
#print("sumR",sumR)
ans = 0
for b in range(N+1):
    z = sumL[b] + sumR[b+1]
    if(b > 0):
        if(b <= N-b):
            ans = max(ans, z+sumL[b-1]+sumR[b+1]-2*sumR[N+1-(N-b-b)])
            #print("A", b, z+sumL[b-1]+sumR[b+1]-2*sumR[N+1-(N-b-b)])
        else:
            ans = max(ans, z+sumL[b-1]+sumR[b+1]-2*sumL[b-(N-b)-1])
            #print("B", b, z+sumL[b-1]+sumR[b+1]-2*sumL[b-(N-b)-1])
    if(b < N):
        if(b >= N-b):
            ans = max(ans, z+sumL[b]+sumR[b+2]-2*sumL[b-(N-b)])
            #print("C", b, z+sumL[b]+sumR[b+2]-2*sumL[b-(N-b)])
            #print(b, z, sumR[b+1], sumL[b], sumR[b+2], sumL[b-(N-b)])
        else:
            ans = max(ans, z+sumL[b]+sumR[b+2]-2*sumR[N+1-(N-b-b)+1])
            #print("D", b, z+sumL[b]+sumR[b+2]-2*sumR[N+1-(N-b-b)+1])
    #print("------------------------")
print(ans)