N=int(eval(input()))

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

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

count=0

for i in range(N):

  fir=min(A[i],B[i])

  count+=fir

  sec=min(A[i+1], max(0,B[i]-fir))

  count+=sec

  A[i+1]-=sec

  

print(count)
N=int(eval(input()))

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

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

SUM=sum(A)

for i in range(N):

    res=B[i]

    fir=min(res,A[i])

    A[i]=A[i]-fir

    res-=fir

    sec=min(res,A[i+1])

    A[i+1]-=sec



print((SUM-sum(A)))
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
for i in range(N):
    fir = min(A[i], B[i])
    count += fir
    sec = min(A[i + 1], max(0, B[i] - fir))
    count += sec
    A[i + 1] -= sec
print(count)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SUM = sum(A)
for i in range(N):
    res = B[i]
    fir = min(res, A[i])
    A[i] = A[i] - fir
    res -= fir
    sec = min(res, A[i + 1])
    A[i + 1] -= sec
print((SUM - sum(A)))

-count = 0 +SUM = sum(A) -    fir = min(A[i], B[i]) -    count += fir -    sec = min(A[i + 1], max(0, B[i] - fir)) -    count += sec +    res = B[i] +    fir = min(res, A[i]) +    A[i] = A[i] - fir +    res -= fir +    sec = min(res, A[i + 1]) -print(count) +print((SUM - sum(A)))