qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
answer=0
for i in range(n):
  if a[i]>=b[i]:
    answer+=b[i]
    a[i]=0
    b[i]=0
  elif a[i]<b[i] and a[i]+a[i+1]>=b[i]:
    answer+=b[i]
    b[i]-=a[i]
    a[i+1]-=b[i]
  elif a[i]<b[i] and a[i]+a[i+1]<b[i]:
    answer+=a[i]
    b[i]-=a[i]
print(answer)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
answer=0
for i in range(n):
  if a[i]>=b[i]:
    answer+=b[i]
    a[i]=0
    b[i]=0
  elif a[i]<b[i] and a[i]+a[i+1]>=b[i]:
    answer+=b[i]
    b[i]-=a[i]
    a[i+1]-=b[i]
  elif a[i]<b[i] and a[i]+a[i+1]<b[i]:
    answer+=(a[i]+a[i+1])
    b[i]-=(a[i]+a[i+1])
    a[i]=0
    a[i+1]=0
print(answer)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))


# In[]
c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count += (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)

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


c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count -= (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
count = 0
for i in range(n+1):
  if a[i] >= b[i]:
    count += b[i]
  else:
    count += b[i]
    a[i+1] = a[i+1] - b[i] + a[i]
print(count) 

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
count = 0
for i in range(n+1):
  if a[i] >= b[i]:
    count += b[i]
  else:
    if a[i] + a[i+1] > b[i]:
      count += b[i]
      a[i+1] = a[i+1] - b[i] + a[i]
    else:
      count += a[i] + a[i+1]
      a[i+1] = 0
print(count)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

def f(ans,n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    ans += nn
    ans += nnn

for i in range(n):
    f(ans, i)

print(ans)


Fixed code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

def f(n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    return nn + nnn

for i in range(n):
    ans += f(i)

print(ans)
Buggy code:

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split())) + [0]
sums = sum(A)
subs = 0
tmp = 0
for i in range(N+1):
    A[i] -= tmp
    cmp = A[i] - B[i]
    if cmp > 0:
        subs += cmp
        tmp = 0
    else:
        tmp = -cmp

ans = sums - subs
    
A.reverse()
B.reverse()
subs = 0
tmp = 0
for i in range(N+1):
    A[i] -= tmp
    cmp = A[i] - B[i]
    if cmp > 0:
        subs += cmp
        tmp = 0
    else:
        tmp = -cmp
    
ans = max(ans,sums-subs)
print(ans)


Fixed code:

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split())) + [0]
sums = sum(A)
subs = 0
tmp = 0
for i in range(N+1):
    A[i] = max(0,A[i]-tmp)
    cmp = A[i] - B[i]
    if cmp > 0:
        subs += cmp
        tmp = 0
    else:
        tmp = -cmp

ans = sums - subs
print(ans)
Buggy code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

sum_beat = 0

for i in range(n):
    if a_list[i] + a_list[i + 1] <= b_list[i]:
        sum_beat += a_list[i] + a_list[i + 1]
        a_list[i + 1] = 0
    else:
        sum_beat += b_list[i]
        a_list[i + 1] = a_list[i + 1] - min(b_list[i] - a_list[i], 0)

print(sum_beat)

Fixed code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

sum_beat = 0

for i in range(n):
    if a_list[i] + a_list[i + 1] <= b_list[i]:
        sum_beat += a_list[i] + a_list[i + 1]
        a_list[i + 1] = 0
    else:
        sum_beat += b_list[i]
        a_list[i + 1] = a_list[i + 1] - max(b_list[i] - a_list[i], 0)

print(sum_beat)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0

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

print(count)

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

sum=0

for i in range(N):
    if B[i]>=A[i]:
        if A[i+1]>=B[i]-A[i]:
            sum+=B[i]
            A[i+1]-=B[i]-A[i]
        else:
            sum+=A[i+1]+A[i]
            A[i+1]=0
    else:
        sum+=B[i]
print(sum)
Buggy code:
a=[]
b=[]
ah=[]
bh=[]
c=int(input())
for x in input().split(" "):
    a.append(int(x))
for x in input().split(" "):
    b.append(int(x))

for x in a:
    ah.append(x)
for x in b:
    bh.append(x)

i=0
n=0

while i<c:
    if ah[i]>bh[i]:
        n+=bh[i]
        ah[i]=ah[i]-bh[i]
    else:
        n+=ah[i]
        ah[i]=0
        bh[i]-=ah[i]
        if ah[i+1]>bh[i]:
            n+=bh[i]
            ah[i+1]-=bh[i]
        else:
            n+=ah[i+1]
            ah[i+1]=0
    i+=1

print(n)

Fixed code:
a=[]
b=[]
ah=[]
bh=[]
c=int(input())
for x in input().split(" "):
    a.append(int(x))
for x in input().split(" "):
    b.append(int(x))

i=0
n=0

while i<c:
    if a[i]>=b[i]:
        n+=b[i]
        a[i]=a[i]-b[i]
    else:
        n+=a[i]
        b[i]-=a[i]
        a[i]=0
        if a[i+1]>=b[i]:
            n+=b[i]
            a[i+1]-=b[i]
        else:
            n+=a[i+1]
            a[i+1]=0
    i+=1

print(n)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

monsall = 0
monsnext = a[0]

for i in range(n):
    print(monsall, monsnext)
    if monsnext >= b[i]:
        monsall += b[i]
        monsnext = a[i+1]
    else:
        if a[i+1] > b[i] - monsnext:
            monsall += b[i]
            monsnext = a[i+1] - b[i] + monsnext
        else:
            monsall += a[i+1] + monsnext
            monsnext = a[i+1]

print(monsall)

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

total = 0
for i in range(n):
    if a[i] - b[i] >= 0:
        total += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            total += b[i]
            a[i+1] -= b[i] - a[i]
        else:
            total += a[i+1] +a[i]
            a[i+1] = 0


print(total)
Buggy code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b.append(0)
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  if a[i]<b[i]:
    cnt+=a[i]
    a[i+1]-=b[i]-a[i]
    cnt+=min(b[i]-a[i+1], a[i+1])
    a[i+1]=max(a[i+1], 0)
print(str(cnt))
  

Fixed code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b.append(0)
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  if a[i]<b[i]:
    cnt+=a[i]
    cnt+=min(b[i]-a[i], a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
print(str(cnt))
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=c=0
for i in range(N+1):
    a=A[i]
    b=B[i]
    ans+=min(a,c)
    a=max(a-c,0)
    ans+=min(a,b)
    c=max(b-a,0)
print(ans)


Fixed code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))+[0]
ans=c=0
for i in range(N+1):
    a=A[i]
    b=B[i]
    ans+=min(a,c)
    a=max(a-c,0)
    ans+=min(a,b)
    c=max(b-a,0)
print(ans)
Buggy code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
pre=sum(A)

for i in range(N):
  if B[i]<=A[i]:
    A[i]-=B[i]
  else:
    A[i+1]=max(0, B[i]-A[i])
    A[i]=0
print(sum(A)-pre)

Fixed code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
pre=sum(A)

for i in range(N):
  if B[i]<=A[i]:
    A[i]-=B[i]
  else:
    A[i+1]=max(0, A[i+1]-B[i]+A[i])
    A[i]=0
print(pre-sum(A))
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
death = 0
tmp = 0
for i,x in enumerate(b):
    if i == 0:
        death += min(a[i]+a[i+1],b[i])
    else:
        death += min(tmp+a[i+1],b[i])
    if (a[i]+a[i+1])<b[i]:
        tmp = 0
    else:
        tmp = a[i]+a[i+1]-b[i]
print(death)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
death = 0
tmp = 0
for i,x in enumerate(b):
    if i == 0:
        death += min(a[i]+a[i+1],b[i])
        if (a[i]+a[i+1])<=b[i]:
            tmp = 0
        else:
            if a[i]>=b[i]:
                tmp = a[i+1]
            else:
                tmp = a[i]+a[i+1]-b[i]
    else:
        death += min(tmp+a[i+1],b[i])
        if (tmp+a[i+1])<=b[i]:
            tmp = 0
        else:
            if tmp>=b[i]:
                tmp = a[i+1]
            else:
                tmp = tmp+a[i+1]-b[i]
    
print(death)
Buggy code:
n = int(input())
a, b = [list(map(int, input().split())) for _ in range(2)]
bSum = 0
for i in range(n):
    if a[i] >= b[i]:
        bSum += b[i]
        a[i] -= b[i]
        b[i] = 0
    elif a[i] + a[i + 1] >= b[i]:
        bSum += b[i]
        a[i] = 0
        a[i + 1] -= b[i] - a[i]
    elif a[i] + a[i + 1] <= b[i]:
        bSum += a[i] + a[i + 1]
        a[i + 1] = 0

print(bSum)


Fixed code:
n = int(input())
a, b = [list(map(int, input().split())) for _ in range(2)]
bSum = 0
for i in range(n):
    if a[i] >= b[i]:
        bSum += b[i]
        a[i] -= b[i]
        b[i] = 0
    elif a[i] + a[i + 1] >= b[i]:
        bSum += b[i]
        a[i + 1] -= b[i] - a[i]
        a[i] = 0
    elif a[i] + a[i + 1] <= b[i]:
        bSum += a[i] + a[i + 1]
        a[i + 1] = 0

print(bSum)
Buggy code:
a = (int)(input())
mons = list(map(int, input().split(" ")))
yuu = list(map(int, input().split(" ")))
count = 0
for i in range(a):
  print(count)
  if yuu[i] >= mons[i]:
    yuu[i] -= mons[i]
    count += mons[i]
    if yuu[i] >= mons[i + 1]:
      yuu[i] -= mons[i + 1]
      count += mons[i + 1]
    else:
      mons[i + 1] -= yuu[i]
      count += yuu[i]
  else:
    mons[i] -= yuu[i]
    count += yuu[i]
print(count)

Fixed code:
a = (int)(input())
mons = list(map(int, input().split(" ")))
yuu = list(map(int, input().split(" ")))
count = 0
for i in range(a):
  if yuu[i] >= mons[i]:
    yuu[i] -= mons[i]
    count += mons[i]
    mons[i] = 0
    if yuu[i] >= mons[i + 1]:
      yuu[i] -= mons[i + 1]
      count += mons[i + 1]
      mons[i + 1] = 0
    else:
      mons[i + 1] -= yuu[i]
      count += yuu[i]
  else:
    mons[i] -= yuu[i]
    count += yuu[i]
    mons[i] -= yuu[i]
print(count)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(a)
for i in range(n):
    if a[i]>=b[i]:
        a[i]-=b[i]
    else:
        if a[i+1]-b[i]-a[i]<0:
            a[i+1]=0
        else:a[i+1]-=b[i]-a[i]

        a[i]=0

print(s-sum(a))

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(a)
for i in range(n):
    if a[i]>=b[i]:
        a[i]-=b[i]
    else:
        if a[i+1]-b[i]+a[i]<0:
            a[i+1]=0
        else:
            a[i+1]-=b[i]-a[i]

        a[i]=0

print(s-sum(a))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

defeat = lambda Ai, Bi: min(A[i], B[i]) 

total = 0
for i in range(len(B)):
    num_of_defeated = defeat(A[i], B[i])
    A[i] -= num_of_defeated
    total += num_of_defeated

    remainder = B[i] - num_of_defeated
    num_of_defeated = defeat(A[i + 1], remainder)
    A[i + 1] -= num_of_defeated
    total += num_of_defeated

print(total)


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

defeat = lambda Ai, Bi: min(Ai, Bi) 

total = 0
for i in range(len(B)):
    num_of_defeated = defeat(A[i], B[i])
    A[i] -= num_of_defeated
    total += num_of_defeated

    remainder = B[i] - num_of_defeated
    num_of_defeated = defeat(A[i + 1], remainder)
    A[i + 1] -= num_of_defeated
    total += num_of_defeated

print(total)
Buggy code:
n = int(input())
enemys = list(map(int,input().split()))
people = list(map(int,input().split()))
print(enemys,people)
count = 0
for i in range(n):
    if enemys[i] - people[i] < 0:
        count += enemys[i]
        people[i]-=enemys[i]
        if enemys[i+1] - people[i] < 0:
            count += enemys[i+1]
            enemys[i+1] = 0
        else:
            count += people[i]
            enemys[i+1] -= people[i]
    else:
        count += people[i]
    
print(count)


Fixed code:
n = int(input())
enemys = list(map(int,input().split()))
people = list(map(int,input().split()))
count = 0
for i in range(n):
    if enemys[i] - people[i] < 0:
        count += enemys[i]
        people[i]-=enemys[i]
        if enemys[i+1] - people[i] < 0:
            count += enemys[i+1]
            enemys[i+1] = 0
        else:
            count += people[i]
            enemys[i+1] -= people[i]
    else:
        count += people[i]
    
print(count)
Buggy code:
n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i == 0:
    kill = min(monster[0],brave[0])
    ans += kill 
    brave -= kill
  else:
    kill = min(monster[i],brave[i])
    ans += kill
    brave[i] -= kill
    kill = min(monster[i+1],brave[i])
    ans += kill
    monster -= kill
print(ans)
    

Fixed code:
n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  kill = min(monster[i],brave[i])
  ans += kill
  brave[i] -= kill
  kill = min(monster[i+1],brave[i])
  ans += kill
  monster[i+1] -= kill
print(ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0

a.append(0)
b.append(0)

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

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0


for i in range(n):
  if(b[i]<=a[i]):
    cnt+=b[i]
    a[i]-=b[i]
  elif(b[i]>a[i] and a[i]+a[i+1]>b[i]):
    cnt+=a[i]
    cnt+=b[i]-a[i]
    a[i+1]-=b[i]-a[i]
    a[i]=0
  else:
    cnt+=a[i]+a[i+1]
    a[i]=0
    a[i+1]=0
    
  #print(a)
    
print(cnt)
Buggy code:

import numpy as np
N = int(input())

A_ls = np.array(list(map(int,input().split(" "))))
B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,b in B_ls:
    if b > A_ls[i]:
        A_ls[i] == 0
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i+1] >= b:
            A_ls[i+1] -=b
            S+=b
        else:
            A_ls[i+1] = 0
            S+=(A_ls[i+1])
    else:
        S += b

print(S)


Fixed code:

import numpy as np
N = int(input())

A_ls = np.array(list(map(int,input().split(" "))))
B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,b in enumerate(B_ls):
    if b > A_ls[i]:
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i+1] >= b:
            A_ls[i+1] -=b
            S+=b
        else:
            S+=A_ls[i+1]
            A_ls[i+1] = 0 
    else:
        S += b

print(S)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
begin = sum(a)
c = 0
for i in range(n):
  a[i] = a[i]-c[i] if a[i]>c[i] else 0
  c = 0
  a[i] = a[i]-b[i] if a[i]>b[i] else 0
  c = b[i] - a[i] if b[i]>a[i] else 0
a[n] = a[n]-c if a[n]>c else 0
after = sum(a)
print(begin-after)


Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
begin = sum(a)
c = 0
for i in range(n):
  a[i] = a[i]-c if a[i]>c else 0
  c = 0
  c = b[i] - a[i] if b[i]>a[i] else 0
  a[i] = a[i]-b[i] if a[i]>b[i] else 0
a[n] = a[n]-c if a[n]>c else 0
after = sum(a)
print(begin-after)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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



Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if b[i] > a[i]:
        ans += a[i]
        b[i] -= a[i]
        if b[i] >= a[i+1]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            a[i+1] -= b[i]
            ans += b[i]
        
    else:
        ans += b[i]

print(ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if(a[i]<=b[i]):
    c+=b[i]
  elif(b[i]>=a[i]+a[i+1]):
    c+=a[i]+a[i+1]
    a[i+1]=0
  else:
    c+=b[i]
    a[i+1]=a[i+1]+a[i]-b[i]
print('{0}'.format(c))

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if(a[i]>b[i]):
    c+=b[i]
  elif(b[i]>=a[i]+a[i+1]):
    c+=a[i]+a[i+1]
    a[i+1]=0
  else:
    c+=b[i]
    a[i+1]=a[i+1]+a[i]-b[i]
print('{0}'.format(c))
Buggy code:

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

guchoku=0
for i,b in enumerate(B):
    t = A[i] - b
    if t <= -1:
        zen = min(A[i+1] - t, 0)
        guchoku += A[i+1] - zen
        A[i+1] = zen
    guchoku += min(A[i], b)
print(guchoku)


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

guchoku=0
for i,b in enumerate(B):
    t = A[i] - b
    if t <= -1:
        zen = max(A[i+1] + t, 0)
        guchoku += A[i+1] - zen
        A[i+1] = zen
    guchoku += min(A[i], b)
print(guchoku)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = list(map(int, input().split()))
print(a, b)
for i in range(n):
    if b[i] >= a[i]:
        b[i] -= a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        continue
    a[i + 1] -= b[i]
    if a[i + 1] < 0:
        a[i + 1] = 0

if a[-1] < 0:
    a[-1] = 0
print(sum_a - sum(a))

Fixed code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = list(map(int, input().split()))
for i in range(n):
    if b[i] >= a[i]:
        b[i] -= a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        continue
    a[i + 1] -= b[i]
    if a[i + 1] < 0:
        a[i + 1] = 0

if a[-1] < 0:
    a[-1] = 0
print(sum_a - sum(a))
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n):
  if b[i] >= a[i] + a[i+1]:
        count += a[i]+a[i+1]
        a[i] = 0
        a[i+1] = 0
  elif b[i] >= a[i]:
    a[i] = 0
    a[i+1] += b[i]-a[i]
    count += b[i]
  else:
    a[i] -= b[i]
    count += b[i]
print(count)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n):
  if b[i] >= a[i] + a[i+1]:
        count += (a[i] + a[i+1])
        a[i] = 0
        a[i+1] = 0
  elif b[i] >= a[i]:
    a[i+1] = a[i] + a[i+1] -b[i]
    a[i] = 0
    count += b[i]
  else:
    a[i] -= b[i]
    count += b[i]
print(count)
Buggy code:
import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 2])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[N - 1])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        over = saver[i] + over - enemy[i]
         
print(beated)

Fixed code:
import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 1])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[0])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        if(over > enemy[i]):
            over = saver[i]
        else:
            over = saver[i] + over - enemy[i]

print(int(beated))
Buggy code:
import copy
N = int(input())
liA = list(map(int,input().split()))
liB = list(map(int,input().split()))
liC = copy.deepcopy(liA)
for i in range(len(liB)):
    if liA[i] >= liB[i]:
        liA[i] = liC[i]-liB[i]
    else:
        liA[i+1] = liC[i+1] + liA[i] - liB[i]
        liA[i] = 0
print(sum(liC) - sum(liA))

Fixed code:
import copy
N = int(input())
liA = list(map(int,input().split()))
liB = list(map(int,input().split()))
liC = copy.deepcopy(liA)
for i in range(len(liB)):
    if liA[i] >= liB[i]:
        liA[i] = liA[i]-liB[i]
    elif liB[i] - (liA[i]+liA[i+1]) <= 0:
        liA[i+1] = liC[i+1] + liA[i] - liB[i]
        liA[i] = 0
    else:
        liA[i] = 0
        liA[i+1] = 0
print(sum(liC)-sum(liA))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0

for i in range(N):

  if A[i] >= B[i]:
    count += B[i]
  else:
    B[i] = B[i] - A[i]
    if B[i] >= A[i+1]:
      count += A[i+1]
    else:
      count += B[i]
    
  
print(count)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
count = 0
 
for i in range(N):
 
  if A[i] >= B[i]:
    count += B[i]
  else:
    B[i] = B[i] - A[i]
    count += A[i]
    if B[i] >= A[i+1]:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] = A[i+1] - B[i]
    
  
print(count)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
  if a[i]+a[i+1] > b[i]:
    cnt += b[i]
    a[i+1] = a[i+1]-(b[i]-a[i])
  else:
    cnt += a[i]+a[i+1]
    a[i+1] = 0
print(cnt)
    

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
  if a[i]+a[i+1] > b[i]:
    cnt += b[i]
    if a[i]<b[i]:
      a[i+1] = a[i+1]-(b[i]-a[i])
  else:
    cnt += a[i]+a[i+1]
    a[i+1] = 0
print(cnt)
Buggy code:
#!/usr/bin/env python


N = input()
N = int(N)

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

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)

#print('N=',N)
#print('A=',A)
#print('B=',B)

monster = 0

for i in range(N+1) :
	if A[i] < B[i] :
		monster = monster + A[i]
		B[i+1] = B[i] - A[i]
	if A[i] >= B[i] :
		monster = monster + B[i]

print(monster)









Fixed code:
#!/usr/bin/env python

N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]
#A.append(0)

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
#B.append(0)

#print('N=',n)
#print('A=',A)
#print('B=',B)

monster = 0

for i in range(N) :
	if A[i] < B[i] :
		monster = monster + A[i]
		B[i] = B[i] - A[i]
		if A[i+1] < B[i] :
			monster = monster + A[i+1]
			A[i+1] = 0
		elif A[i+1] >= B[i] :
			monster = monster + B[i]
			A[i+1] = A[i+1] - B[i]
	elif A[i] >= B[i] :
		monster = monster + B[i]

print(monster)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0

for i in range(N):
    if A[i] == 0:
        continue
    if A[i] >= B[i]:
        cnt += B[i]
    else:
        cnt += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            cnt += B[i]
            A[i+1] -= B[i]
        else:
            cnt += A[i+1]
            A[i+1] = 0

print(cnt)

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

mons=0
for i in range(N):
  if B[i]>A[i]:
    mons+=A[i]
    if B[i]>=A[i]+A[i+1]:
      mons+=A[i+1]
      A[i+1]=0
    else:
      mons+=B[i]-A[i]
      A[i+1]-=B[i]-A[i]
  else:
    mons+=B[i]
print(mons)