qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
tmp = 0
for i in range(N):
    tmp_mon = max(A[i] - tmp, 0)
    cnt += min(B[i], tmp_mon) + tmp
    if B[i] > tmp_mon:
        tmp = B[i] - tmp_mon
    elif B[i] <= tmp_mon:
        tmp = 0

cnt += min(A[-1], tmp)

print(cnt)

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

cnt = 0
tmp = 0
for i in range(N):
    tmp_mon = max(A[i] - tmp, 0)
    killed_mon = min(A[i], tmp)
    cnt += min(B[i], tmp_mon) + killed_mon

    if B[i] > tmp_mon:
        tmp = B[i] - tmp_mon
    elif B[i] <= tmp_mon:
        tmp = 0

cnt += min(A[-1], tmp)

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

score = 0
for i in range(n):
	if B[i] >= A[i] + A[i+1]:
		score = score + A[i] + A[i+1]
        A[i+1] = 0
	elif B[i] <= A[i]:
		score = score + B[i]
	else:
		score = score + B[i]
		A[i+1] = A[i+1] + A[i] - B[i]
print(score)

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

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

ans = 0
L = 0
for i in range(N):
    ans += min(B[i] + L, A[i])
    L = max(B[i] - A[i], 0)
if L > 0:
    ans += min(L, A[N])
print(ans)

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

ans = 0
L = 0
for i in range(N):
    ans += min(B[i] + L, A[i])
    L = max(B[i] - max(A[i] - L, 0), 0)
if L > 0:
    ans += min(L, A[N])
print(ans)
Buggy code:
N=int(input())
a=input().split()
b=input().split()
for i in range(0,N):
  a[i]=int(a[i])
  b[i]=int(b[i])
a[N]=int(a[N])
answer=sum(a)
for i in range(0,N):
    c=b[i]-a[i]
    if c<0:
        a[i]=-c
        b[i]=0
    else:
        a[i]=0
        b[i]=c
    d=b[i]-a[i+1]
    if d<0:
        a[i+1]=-c
        b[i]=0
    else:
        a[i+1]=0
        b[i]=c
print (answer-sum(a))

Fixed code:
N=int(input())
a=input().split()
b=input().split()
for i in range(0,N):
  a[i]=int(a[i])
  b[i]=int(b[i])
a[N]=int(a[N])
answer=sum(a)
for i in range(0,N):
    c=b[i]-a[i]
    if c<0:
        a[i]=-c
        b[i]=0
    else:
        a[i]=0
        b[i]=c
    d=b[i]-a[i+1]
    if d<0:
        a[i+1]=-d
        b[i]=0
    else:
        a[i+1]=0
        b[i]=d
print (answer-sum(a))
Buggy code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
amari = 0
ans = 0
for i in range(N):
    can_kill = amari + Blist[i]
    enemy = Alist[i]
    if can_kill > enemy:
        ans += enemy
        amari = max(Blist[i] - enemy, 0)
    else:
        ans += can_kill
        amari = 0
if amari > Alist[-1]:
    ans += Alist[-1]
else:
    ans += amari
print(ans)


Fixed code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
amari = 0
ans = 0
for i in range(N):
    can_kill = Blist[i]
    enemy = Alist[i]
    if can_kill > enemy:
        Alist[i] = 0
        ans += enemy
        amari = Blist[i] - enemy
    else:
        Alist[i] -= can_kill
        ans += can_kill
        amari = 0
    if Alist[i + 1] > amari:
        ans += amari
        Alist[i + 1] -= amari
    else:
        ans += Alist[i + 1]
        Alist[i + 1] = 0
    # print(Alist, ans)
print(ans)
Buggy code:
# coding: utf-8
# Your code here!
N=int(input())

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

count=0
for i in range(N):
    hiku=min(A[i],B[i])
    count+=hiku
    A[i]-=hiku
    B[i]-=hiku
    hiku=min(A[i+1],B[i])
    count+=hiku
    A[i+1]-=hiku
    B[i]-=hiku

print(A)
print(B)
print(count)



Fixed code:
# coding: utf-8
# Your code here!
N=int(input())

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

count=0
for i in range(N):
    hiku=min(A[i],B[i])
    count+=hiku
    A[i]-=hiku
    B[i]-=hiku
    hiku=min(A[i+1],B[i])
    count+=hiku
    A[i+1]-=hiku
    B[i]-=hiku

print(count)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(len(B)):
  if A[i] - B[i] >= 0:
    A[i] = A[i] - B[i]
    ans += B[i]
  else:
    ans += A[i]
    A[i] = 0
    if A[i+1] - (B[i] - A[i]) >= 0:
      A[i+1] = A[i+1] - (B[i] - A[i])
      ans += (B[i] - A[i])
    else:
      ans += A[i+1]
      A[i+1] = 0
  #print(ans, A)
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(len(B)):
  if A[i] - B[i] >= 0:
    A[i] = A[i] - B[i]
    ans += B[i]
  else:
    ans += A[i]
    if A[i+1] - (B[i] - A[i]) >= 0:
      A[i+1] = A[i+1] - (B[i] - A[i])
      ans += (B[i] - A[i])
    else:
      ans += A[i+1]
      A[i+1] = 0
    A[i] = 0
  #print(ans, A)
print(ans)
Buggy code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<remain:
        ans1+=B[i]
        remain=A[i+1]
    if B[i]>=remain:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
print(ans1)

Fixed code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<remain:
        ans1+=B[i]
        remain=A[i+1]
    else:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
print(ans1)
Buggy code:
N = int(input())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
for i in range(N-1):
  if List_A[i] >= List_B[i]:
    res += List_B[i]
  else:
    res += List_A[i]
    if List_A[i+1] >= List_B[i]-List_A[i]:
      res += List_B[i]-List_A[i]
      List_A[i+1] = List_A[i+1] - List_B[i] +List_A[i]
    else:
      res += List_A[i+1]
      List_A[i+1] = 0
print(res)

Fixed code:
N = int(input())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
for i in range(N):
  if List_A[i] >= List_B[i]:
    res += List_B[i]
  else:
    res += List_A[i]
    if List_A[i+1] >= List_B[i]-List_A[i]:
      res += List_B[i]-List_A[i]
      List_A[i+1] = List_A[i+1] - List_B[i] +List_A[i]
    else:
      res += List_A[i+1]
      List_A[i+1] = 0
print(res)
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 b[i]>=a[i]:
        cnt += a[i]
        b[i] -= a[i]
        a[i+1] -= min(b[i],a[i+1])
        cnt += min(b[i],a[i+1])
    
    else:
        cnt += b[i]
print(cnt)
    

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]:
        a[i] = a[i] - b[i]
        count = count + b[i]
        b[i] = 0
    else:
        b[i] = b[i] - a[i]
        count = count + a[i]
        a[i] = 0
        count = count + min(a[i + 1], b[i])
        a[i + 1] = a[i + 1] - min(a[i + 1], b[i])

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

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

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

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

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

B=B+[0]
counter = 0
print(B) 
for i in reversed(range(1, N+1)):
    dif = A[i] - B[i]
    if dif > 0:
        B[i] += min(dif, B[i-1])
        B[i-1] -= min(dif, B[i-1]) 
    counter += min(A[i], B[i])
counter += min(A[i-1], B[i-1])    
print(counter)

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

B=B+[0]
counter = 0
for i in reversed(range(1, N+1)):
    dif = A[i] - B[i]
    if dif > 0:
        B[i] += min(dif, B[i-1])
        B[i-1] -= min(dif, B[i-1]) 
    counter += min(A[i], B[i])
counter += min(A[i-1], B[i-1])    
print(counter)
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 B[i] <= A[i]:
        cnt += B[i]
        B[i] = 0
        A[i] = 0
    else:
        cnt += min(B[i],A[i]+A[i+1])
        A[i] = 0
        A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
    # print(A)
    # print(B)
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] = A[i]-B[i]
        B[i] = 0
    else:
        cnt += min(B[i],A[i]+A[i+1])
        A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
        A[i] = 0
        B[i] = B[i] - min(B[i],A[i]+A[i+1])
    # print(A)
    # print(B)
print(cnt)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
ad = 0

for i in range(N):
  if A[i] <= B[i] + ad:
    count += A[i]
    ad = max(0, B[i] + ad - A[i])
    #print(count, ad)
  else:
    count += A[i] - (B[i] + ad)
    ad = 0
    #print(count, ad)

count += min(A[N], ad)     

print(count)

Fixed code:

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

for i in range(N):
  if A[i] <= B[i] + ad:
    count += A[i]
    ad = max(0, B[i] - max(A[i] - ad, 0))
    #print(count, ad)
  else:
    count += B[i] + ad
    ad = 0
    #print(count, ad)

count += min(A[N], ad)     

print(count)
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 a[i] >= c[i]:
        ans += c[i]
        a[i] -= c[i]
    else:
        ans += a[i]
        a[i] = 0
        
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        c[i+1] = b[i]-a[i]
ans += c[n]
print(ans)

Fixed 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 a[i] >= c[i]:
        ans += c[i]
        a[i] -= c[i]
    else:
        ans += a[i]
        a[i] = 0
        
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        c[i+1] = b[i]-a[i]
if a[n] >= c[n]:
    ans += c[n]
else:
    ans += a[n]
print(ans)
Buggy code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
A = i_l()
B = i_l()

ans = 0
for i in range(len(B)):
    print('ans', ans)
    if A[i] >= B[i]:
        ans += B[i]
        A[i] -= B[i]
        B[i] = 0
    else:
        ans += A[i]
        B[i] = B[i] - A[i]
        A[i] = 0
        if A[i+1] >= B[i]:
            ans += B[i]
            A[i+1] = A[i+1] - B[i]
            B[i] = 0
        else:
            ans += A[i+1]
            B[i] = B[i] - A[i+1]
            A[i+1] = 0

print(ans)


Fixed code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
A = i_l()
B = i_l()

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

print(ans)
Buggy 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 += b[i]
        b[i] = 0
    else:
        a[i] = 0
        ans += a[i]
        c = b[i] - a[i]
        if c > a[i+1]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            a[i+1] - c
            ans += c


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] + a[i+1]:
          ans += a[i] + a[i+1]
          a[i+1] = 0
     elif a[i] <= b[i] <=a[i] + a[i+1]:
          ans += b[i]
          a[i+1] = a[i] + a[i+1] - 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()))
ans = 0
for i in range(N):
    ans += min(B[i],A[i]+A[i+1])
    if B[i]>A[i]:
        A[i+1] = max(0,B[i]-A[i])
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):
    ans += min(B[i],A[i]+A[i+1])
    if B[i]>A[i]:
        A[i+1] = max(A[i+1]-(B[i]-A[i]),0)
print(ans)
Buggy code:
N = int(input())
An = map(int,input().split())
Bn = map(int,input().split())
ans=0
for b in range(len(Bn)):
    left = min(An[b],Bn[b])
    ans+=left
    An[b]-=left
    Bn[b]-=left
    right = min(An[b+1],Bn[b])
    ans+=right
    An[b+1]-=right
    Bn[b]-=right
print(ans)


Fixed code:
N = int(input())
An = list(map(int,input().split()))
Bn = list(map(int,input().split()))
ans=0
for b in range(len(Bn)):
    left = min(An[b],Bn[b])
    ans+=left
    An[b]-=left
    Bn[b]-=left
    right = min(An[b+1],Bn[b])
    ans+=right
    An[b+1]-=right
    Bn[b]-=right
print(ans)
Buggy 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]
        if B[i] - A[i] > A[i + 1]:
            ans += A[i + 1]
        else:
            A[i + 1] -= B[i] - A[i]
            ans += B[i] - A[i]
    else:
        ans += B[i]

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]
        if B[i] - A[i] > A[i + 1]:
            ans += A[i + 1]
            A[i + 1] = 0
        else:
            ans += B[i] - A[i]
            A[i + 1] -= B[i] - A[i]
    else:
        ans += B[i]

print(ans)
Buggy code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
cnt = 0

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

Fixed code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
cnt = 0

for i in range(N):
    if A[i]+A[i+1] >= B[i]:
        if A[i]>B[i]:
            cnt += B[i]
        else:
            A[i+1] = A[i]+A[i+1] - B[i]
            cnt += B[i]
    else:
        cnt += A[i]+A[i+1]
        A[i+1] = 0
    
print(cnt)
Buggy code:
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=list(intinput())
ans=0
print(a)
for i in range(n):
    if a[i]+a[i+1]<b[i]:
        ans+=a[i]+a[i+1]
        a[i+1]=0
        print(a,0)
    else:
        ans+=b[i]
        a[i+1]-=0 if a[i]-b[i]>0 else b[i]-a[i]
        print(a,1)
print(ans)

Fixed code:
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


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

ans = 0
for i in range(n):
  if a[i] >= b[i]:
    ans += b[i]
    break
  else:
    if a[i] + a[i+1] <= b[i]:
      ans += a[i] + a[i+1]
      a[i+1] = 0
    else:
      ans += b[i]
      a[i+1] -= b[i] - a[i]
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 a[i] >= b[i]:
    ans += b[i]
  else:
    if a[i] + a[i+1] <= b[i]:
      ans += a[i] + a[i+1]
      a[i+1] = 0
    else:
      ans += b[i]
      a[i+1] -= b[i] - a[i]
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            print(ans)
            ans += B[i]
            print(ans)
            A[i+1] = (A[i] + A[i+1]) - B[i]
    print(A,ans)
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 A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            ans += B[i]
            A[i+1] = (A[i] + A[i+1]) - B[i]
print(ans)
Buggy code:
import math
import re
import copy
import sys
import numpy as np

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

for i in range(n):
    c += min(a[i],b[i])
    if a[i] < b[i]:
        a[i+1] -= b[i]-a[i]
        c += b[i]-a[i]

print(c)

Fixed code:
import math
import re
import copy
import sys

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

for i in range(n):
    c += min(a[i],b[i])
    if a[i] < b[i]:
        c += min(a[i+1],b[i]-a[i])
        a[i+1] -= min(a[i+1],b[i]-a[i])

print(c)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Max=0
for i in range(N):
  if A[i]>=B[i]:
    Max+=B[i]
  else:
    B[i]-=A[i]
    if A[i+1]>=B[i]:
      A[i+1]-=B[i]
      Max+=A[i]+B[i]
    else:
      A[i+1]=0
      Max+=A[i]+A[i+1]
print(Max)

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+1]=0
    elif B[i]>A[i]:
        count +=B[i]
        A[i+1] -= B[i]-A[i]
    else:
        count +=B[i]

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

beaten_monster_num = 0

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

print(int(beaten_monster_num))

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+=b[i]
    else:
        ans+=a[i]
        b[i]-=a[i]
        if a[i+1]>b[i]:
            ans+=b[i]
            a[i+1]-=b[i]
        else:
            ans+=a[i+1]
            a[i+1]=0
print(ans)
Buggy code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
ans = 0
num = 0
for i in range(n+1):
  if num != 0:
    if A[i] - num <= 0:
      num = B[i]
      ans += A[i]
    else:
      A[i] -= num
      num = 0
      if A[i] >= B[i]:
        num = 0
        ans += B[i]
      else:
        num = B[i]-A[i]
        ans += A[i]
  else:
    if A[i] >= B[i]:
      num = 0
      ans += B[i]
    else:
      num = B[i]-A[i]
      ans += A[i]
print(ans)

Fixed code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
ans = 0
num = 0
for i in range(n+1):
  if num != 0:
    if A[i] - num <= 0:
      num = B[i]
      ans += A[i]
    else:
      a = A[i]
      b = num
      A[i] -= num
      num = 0
      if A[i] >= B[i]:
        num = 0
        ans += (B[i]+b)
      else:
        num = B[i]-A[i]
        ans += a
  else:
    if A[i] >= B[i]:
      num = 0
      ans += B[i]
    else:
      num = B[i]-A[i]
      ans += A[i]
print(ans)
Buggy code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        if a[i]<b[i]+n:
            res += a[i]
        else:
            res += b[i]+n
        if a[i]-n>0:
            c = a[i]-n
        else:
            c = 0
        if b[i]-c>0:
            n = b[i]-c
        else:
            b = 0
    res += min(n, a[-1])
    print(res)

if __name__ == '__main__':
    main()

Fixed code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        res += min(a[i], b[i]+n)
        c = max(a[i]-n, 0)
        n = max(b[i]-c, 0)
    res += min(n, a[-1])
    print(res)

if __name__ == '__main__':
    main()
Buggy code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

result = 0

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

Fixed code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)


result = 0

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