qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
monsters=list(map(int, input().split()))
battle=list(map(int, input().split()))
remain=0
win=0
for i in range(n):
    if remain != 0:
        win += remai
        battle[i] -= remain
        remain = 0
    if monsters[i] < battle[i]:
        win += monsters[i]
        monsters[i+1] -= battle[i] - monsters[i]
    else:
        win += battle[i]
        remain = monsters[i] - battle[i]
print(win)

Fixed code:
n=int(input())
monsters=list(map(int, input().split()))
battle=list(map(int, input().split()))
remain=0
win=0
for i in range(n):
    if monsters[i] < battle[i]:
        win += monsters[i]
        if monsters[i+1] >= battle[i] - monsters[i]:
            win += battle[i] - monsters[i]
            monsters[i+1] -= battle[i] - monsters[i]
        else:
            win += monsters[i+1]
            monsters[i+1] = 0
    else:
        win += battle[i]
print(win)
Buggy code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

r_monster = 0
r_yusya = 0
monster_cnt = 0

if A[-1] > B[-1]:
    monster_cnt += B[-1]
    B[-1] = 0
else:
    monster_cnt += A[-1]
    B[-1] -= A[-1]
    A[-1] = 0
for a, b in zip(reversed(A[:-1]), reversed(B)):
    if a+r_monster > b+r_yusya:
        monster_cnt += b+r_yusya
        r_yusya = 0
        r_monster = min(a+r_monster - b - r_yusya, a)
    else:
        monster_cnt += a+r_monster
        r_yusya = min(b+r_yusya - a - r_monster, b)
        r_monster = 0

print(monster_cnt)


Fixed code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

r_monster = 0
monster_cnt = 0

if A[-1] > B[-1]:
    monster_cnt += B[-1]
    B[-1] = 0
else:
    monster_cnt += A[-1]
    B[-1] -= A[-1]
for a, b in zip(reversed(A[:-1]), reversed(B)):
    if a+r_monster > b:
        monster_cnt += b
        r_monster = min(a+r_monster - b, a)
    else:
        monster_cnt += a+r_monster
        r_monster = 0

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

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]:
        t=b[i]
        a[i] -= t
        b[i] -= t
        ans += t
    else:
        t=a[i]
        a[i] -= t
        b[i] -= t
        ans += t

    if a[i + 1] >= b[i]:
        t=b[i]
        a[i+1]-=t
        b[i] -= t
        ans += t
    else:
        t = a[i + 1]
        a[i+1]-=t
        b[i] -= t
        ans+=t
print(ans)
Buggy code:
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
total = 0
for i in range(n):
    if B[i] >= A[i]:
        total += A[i]
        B[i] -= A[i]
        if A[i+1]- B[i] - A[i] < 0:
            total += A[i+1]
        else:
            total+= B[i]
            A[i+1] -= B[i]
    else:
        total += B[i]
print(total)

Fixed code:
n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
total = 0
for i in range(n):
    if B[i] >= A[i]:
        total += A[i]
        B[i] -= A[i]
        if A[i+1] < B[i] :
            total += A[i+1]
            A[i+1] = 0
        else:
            total+= B[i]
            A[i+1] -= B[i]
    else:
        total += B[i]
print(total)
Buggy code:
N = int(input())
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = A[0]
d = 0
for i in range(N):
    d += max(0, c - B[i])
    c = max(0, A[i+1] + min(0, c - B[i]))
    
print(sum(A) - (d + c))

Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = 0
c = A[0]

for i in range(N):
    d += max(0, c - B[i])
    c = max(0, A[i+1] + min(0, c - B[i]))
            
            
print(sum(A) - (d + c))
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] > B[i]:
        cnt += B[i]
        A[i] -= B[i]
        B[i] = 0
        
    else:
        cnt += A[i]
        A[i] = 0
        B[i] -= A[i]
        
            
    if A[i+1] > B[i]:
        cnt += B[i]
        A[i+1] -= B[i]
        B[i] = 0
        
    else:
        cnt += A[i+1]
        A[i+1] = 0
        B[i] -= A[i+1]
        
        
       
cnt += min(A[-1],B[-1]) 


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

    #print(A)
    #print(B)
    #print(cnt)
    #print('')
        
       
cnt += min(A[-1],B[-1]) 


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

power = 0
monster = 0
if A[0] > B[0]:
  reslut = B[0]
  kurikoshi = 0
else:
  reslut = A[0]
  kurikoshi = B[0] - A[0]  

for i in range(1, N):
  if A[i] - kurikoshi > 0:
    nokori = A[i] - kurikoshi
    result += kurikoshi
    if nokori > B[i]:
      result += B[i]
      kurikoshi = 0
    else:
      result += nokori
      kurikoshi = B[i] - nokori
  elif A[i] - kurikoshi <= 0:
    result += A[i]
    kurikoshi = B[i]
if A[N] > kurikoshi:
  result += kurikoshi
  print(result)
else:
  result += A[N]
  print(result)
  

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

if A[0] > B[0]:
  result = B[0]
  kurikoshi = 0
else:
  result = A[0]
  kurikoshi = B[0] - A[0]  

for i in range(1, N):
  if A[i] - kurikoshi > 0:
    nokori = A[i] - kurikoshi
    result += kurikoshi
    if nokori > B[i]:
      result += B[i]
      kurikoshi = 0
    else:
      result += nokori
      kurikoshi = B[i] - nokori
  elif A[i] - kurikoshi <= 0:
    result += A[i]
    kurikoshi = B[i]
if A[N] > kurikoshi:
  result += kurikoshi
  print(result)
else:
  result += A[N]
  print(result)
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] >= 0:
        ans += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            ans += b[i]
            a[i+1] = a[i+1] - b[i] - a[i]
        else:
            ans += a[i+1] + a[i]
            a[i+1] = 0
print(ans)

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

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

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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

if A[N] <= B[N-1]:
  kill += A[N]
else:
  kill += B[N-1]

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

def battle(a,ai,b):
  if a+ai <= b:
    ai=0
    count=a+ai
  elif a<=b:
    ai=ai-(b-a)
    count=b
  else:
    ai=ai
    count=b
  result ai,count
  
for i in range(n):
  c=0
  a[i+1],c=battle(a[i],a[i+1],b[i])
  count += c

print(count)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=0
def battle(a,ai,b):
  if a+ai <= b:
    count=a+ai
    ai=0
  elif a<=b:
    ai=ai-(b-a)
    count=b
  else:
    ai=ai
    count=b
  return ai,count
  
for i in range(n):
  c=0
  a[i+1],c=battle(a[i],a[i+1],b[i])
  count += c
 
print(count)
Buggy code:
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

print(A)
print(B)
# print(P_true)
def_Bsum = sum(B)

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

    if(0<i<N):
        if(A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0

            if (A[i] < B[i]):
                B[i] -= A[i]
                A[i] = 0
            else:
                A[i] -= B[i]
                B[i] = 0

    if(i==N):
        if (A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0


ans = def_Bsum - sum(B)
# print(def_Bsum)
# print(sum(B))

print(ans)




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

# print(A)
# print(B)
# print(P_true)
def_Bsum = sum(B)

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

    if(0<i<N):
        if(A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0

            if (A[i] < B[i]):
                B[i] -= A[i]
                A[i] = 0
            else:
                A[i] -= B[i]
                B[i] = 0

    if(i==N):
        if (A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0


ans = def_Bsum - sum(B)
# print(def_Bsum)
# print(sum(B))

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):
    ab = a[i] - b[i]
    
    if ab < 0:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        b[i] = abs(ab)
        ab = a[i+1] - b[i]
        
        if ab <= 0:
            ans += a[i+1]
            a[i+1] = 0
            b[i] = abs(ab) 
        else:
            ans += b[i]
           
    elif ab == 0:
        ans += b[i]
        a[i] = 0
        b[i] = 0
        
    else:
        ans += 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):
    ab = a[i] - b[i]
    
    if ab < 0:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        b[i] = abs(ab)
        ab = a[i+1] - b[i]
        
        if ab <= 0:
            ans += a[i+1]
            a[i+1] = 0
            b[i] = abs(ab)
        else:
            ans += b[i]
            a[i+1] -= b[i]
            b[i] = 0
           
    elif ab == 0:
        ans += b[i]
        a[i] = 0
        b[i] = 0
        
    else:
        ans += b[i]
        b[i] = 0
        
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = sum(A)

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

print(ans - sum(A))

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

ans = sum(A)

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

print(ans - sum(A))
Buggy code:
#

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0)
b.append(0)
z = 0
c = b[0]
for i in range(n+1):
    x = a[i] - c
    #print(z)
    if x <= 0:
        z += a[i]
        #print(a[i])
        if -x >= a[i+1]:
            c = b[i+1] + a[i+1]
        elif -x < a[i+1]:
            c = b[i+1] - x
    elif x > 0:
        z += c
        #print(c)
        c = b[i+1]

print(z)


Fixed code:
#

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

flag=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
print(ans)


Fixed code:
n=int(input())
l=list(map(int,input().split()))
la=list(map(int,input().split()))

ans=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
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):
    town_a = a[i]
    town_b = b[i+1]
    power = b[i]
    if power > town_a:
        ans += town_a
        power -= town_a
    else:
        ans += power
        continue
    if power > town_b:
        ans += town_b
        a[i+1] = 0
    else:
        ans += power
        a[i+1] -= power
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):
    town_a = a[i]
    town_b = a[i+1]
    power = b[i]
    if power > town_a:
        ans += town_a
        power -= town_a
    else:
        ans += power
        continue
    if power > town_b:
        ans += town_b
        a[i+1] = 0
    else:
        ans += power
        a[i+1] -= power
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] + A[i+1] < B[i]:
        Ans += A[i]
        A[i+1] = 0
    elif A[i] >= B[i]:
        Ans += B[i]
    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()))
x=0
for i in range(N):
  if A[i]+A[i+1]<=B[i]:
    x+=A[i]+A[i+1]
    A[i+1]=0
  elif A[i]>=B[i]:
    x+=B[i]
  elif A[i]<B[i]:
    x+=B[i]
    A[i+1]=A[i]+A[i+1]-B[i]
print(x)
Buggy code:
N=int(input())
a=list(map(int,input().split()))
B=list(map(int,input().split()))
A=a.copy()
for i in range(N-1,-1,-1):
  if A[i+1]-B[i]<=0:
    A[i+1]=0
    if A[i]-A[i+1]+B[i]>=0:
      A[i]=A[i]+A[i+1]-B[i]
    else:
      A[i]=0
  else:
    A[i+1]=A[i+1]-B[i]
print(sum(a)-sum(A))

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

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

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:
        ans+=a[i]
        b[i]-=a[i]
        if a[i+1]<b[i]:
            ans+=a[i+1]
            a[i+1]=0
        else:
            ans+=b[i]
            a[i+1]-=b[i]
print(ans)
Buggy code:
n=int(input())
a=([int(n) for n in input().split()])
b=([int(n) for n in input().split()])
b.append(0)
r=0
t=0
x=0
for i in range(n+1):
  t=b[i]+x-a[i]
  if t>=0:
    r=r+a[i]
    x=max(b[i],t)
  else:
    r=r+b[i]+x
    x=0
print(r)

Fixed code:
n=int(input())
a=([int(n) for n in input().split()])
b=([int(n) for n in input().split()])
b.append(0)
r=0
t=0
x=0
for i in range(n+1):
  t=b[i]+x-a[i]
  if t>=0:
    r=r+a[i]
    x=min(b[i],t)
  else:
    r=r+b[i]+x
    x=0
print(r)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0

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

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0
 
for i in range(n):
  if a[i] >= b[i]:
    c += b[i]
  else:
    c += a[i]
    c += min(a[i+1],b[i]-a[i])
    if a[i+1] >= b[i]-a[i]:
      a[i+1] = a[i+1] - (b[i] - a[i])
    else:
      a[i+1] = 0
     
print(c)
Buggy code:
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0

print(a)
print(b)

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

print(t)


Fixed code:
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0

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

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

monster = 0
addPower = 0

for i in range(N):
    #print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        #print(':', end='')
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    elif BA > 0:
        #print('%', end='')
        monster += B[i]
        A[i+1] -= min(A[i+1], B[i])
    else:
        #print('@', end='')
        monster += B[i]

print(monster)

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

monster = 0
addPower = 0

for i in range(N):
    #print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        #print(':', end='')
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    elif BA > 0:
        #print('%', end='')
        monster += B[i]
        A[i+1] -= min(A[i+1], BA)
    else:
        #print('@', end='')
        monster += B[i]
print(monster)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

answer = 0

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

        if A[i] < B[i-1]:
            answer += A[i]
            B[i-1] -= A[i]
            A[i] = 0

        else:
            answer += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0

    else:
        if A[i] < B[i] + B[i-1]:
            answer += A[i]
            if A[i] < B[i-1]:
                B[i-1] -= A[i]
                A[i] = 0
            else:
                B[i-1] = 0
                B[i] -= (A[i]-B[i-1])
                A[i] = 0
        else:
            answer += (B[i]+B[i-1])
            A[i] -= (B[i]+B[i-1])
            B[i],B[i-1] = 0,0

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

        if A[i] < B[i-1]:
            answer += A[i]
            B[i-1] -= A[i]
            A[i] = 0

        else:
            answer += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0

    else:
        if A[i] < B[i] + B[i-1]:
            answer += A[i]
            if A[i] < B[i-1]:
                B[i-1] -= A[i]
                A[i] = 0
            else:
                B[i] -= (A[i]-B[i-1])
                B[i-1] = 0
                A[i] = 0
        else:
            answer += (B[i]+B[i-1])
            A[i] -= (B[i]+B[i-1])
            B[i],B[i-1] = 0,0

print(answer)
Buggy code:
 = 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]:
    ab = b[i] - a[i]
    if a[i+1] > ab:
      ans += b[i]
      a[i+1] -= ab
    else:
      ans += a[i] + a[i+1]
      a[i+1] = 0
  else:
    ans += b[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:
        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]
print(ans)
Buggy code:
n = int(input())

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if bl[i] <= al[i]:
        ans += bl[i]
    elif bl[i] > al[i] and bl[i] <= al[i] + al[i+1]:
        ans += bl[i]
        al[i+1] = al[i] + al[i+i] - bl[i]
    else:
        ans += al[i] + al[i+1]
        al[i+1] == 0
        
print(ans)
        

Fixed code:
n = int(input())
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if al[i] > bl[i]:
        ans += bl[i]
    elif al[i] + al[i+1] > bl[i]:
        ans += bl[i]
        al[i+1] = al[i+1] + al[i] - bl[i]
    else:
        ans += al[i] + al[i+1]
        al[i+1] = 0
        
print(ans)
Buggy code:
def LI():
  return [int(s) for s in input().split()]

N = int(input())

A_s = LI()
B_s = LI()

counter = 0

for i in range(N):
  if A_s[i] > B_s[i]:
    counter+=(A_s[i]-B_s[i])
  elif B_s[i] < A_s[i] + A_s[i+1]:
    counter+=B_s[i]
    A_s[i+1] = A_s[i+1] - (B_s[i]-A_s[i])
  else:
    counter+=A_s[i]+A_s[i+1]
    A_s[i+1] = 0
    
print(counter)

Fixed code:
def LI():
  return [int(s) for s in input().split()]

N = int(input())

A_s = LI()
B_s = LI()

counter = 0

for i in range(N):
  if A_s[i] > B_s[i]:
    counter+=B_s[i]
  elif B_s[i] < A_s[i] + A_s[i+1]:
    counter+=B_s[i]
    A_s[i+1] = A_s[i+1] - (B_s[i]-A_s[i])
  else:
    counter+=A_s[i]+A_s[i+1]
    A_s[i+1] = 0
    
print(counter)