Buggy python submission (verdict: Runtime Error):
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
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]:
        if A[i] >= B[i+1]+B[i]:
            ans += B[i]+B[i+1]
            B[i+1] = 0
        else:
            B[i+1] -= A[i]-B[i]
            ans += A[i]
    else:
        ans += A[i]

print(ans)

Fixed submission:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
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]:
        if B[i] >= A[i+1]+A[i]:
            ans += A[i]+A[i+1]
            A[i+1] = 0
        else:
            A[i+1] -= B[i]-A[i]
            ans += B[i]
    else:
        ans += B[i]

print(ans)

Buggy python submission (verdict: Runtime Error):
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

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

print(ans)

Fixed submission:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
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]:
        if B[i] >= A[i+1]+A[i]:
            ans += A[i]+A[i+1]
            A[i+1] = 0
        else:
            A[i+1] -= B[i]-A[i]
            ans += B[i]
    else:
        ans += B[i]

print(ans)

Buggy python submission (verdict: Runtime Error):

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
    else:
        yojo = B[1]
        Ans += A[0]
        chinpo = False
        #A[0]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下

for i in range(1,N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        Ans += A[i]
        yojo = B[i]
        chinpo = True

if yojo > A[N]:
    Ans += A[N]
else:
    if yojo + B[N-1] > A[N]:
        Ans += A[N]
    else:
        Ans += yojo + B[N-1]

print(Ans)

　

Fixed submission:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
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]:
        if B[i] >= A[i+1]+A[i]:
            ans += A[i]+A[i+1]
            A[i+1] = 0
        else:
            A[i+1] -= B[i]-A[i]
            ans += B[i]
    else:
        ans += B[i]

print(ans)