N=int(eval(input()))

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

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

ans=0

for i in range(N):

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

  ans+=left

  A[i]-=left

  B[i]-=left

  right=min(A[i+1],B[i])

  ans+=right

  A[i+1]-=right

  B[i]-=right

print(ans)
n = int(eval(input()))

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

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



killed = 0



for i in range(n):

    now_kill = min(a[i], b[i])

    killed += now_kill

    #a[i] -= now_kill

    b[i] -= now_kill

    if b[i] == 0:continue

    now_kill = min(a[i+1], b[i])

    killed += now_kill

    a[i+1] -= now_kill

    #b[i] -= now_kill



print(killed)
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    left = min(A[i], B[i])
    ans += left
    A[i] -= left
    B[i] -= left
    right = min(A[i + 1], B[i])
    ans += right
    A[i + 1] -= right
    B[i] -= right
print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
killed = 0
for i in range(n):
    now_kill = min(a[i], b[i])
    killed += now_kill
    # a[i] -= now_kill
    b[i] -= now_kill
    if b[i] == 0:
        continue
    now_kill = min(a[i + 1], b[i])
    killed += now_kill
    a[i + 1] -= now_kill
    # b[i] -= now_kill
print(killed)

-N = int(eval(input())) -A = list(map(int, input().split())) -B = list(map(int, input().split())) -ans = 0 -for i in range(N): -    left = min(A[i], B[i]) -    ans += left -    A[i] -= left -    B[i] -= left -    right = min(A[i + 1], B[i]) -    ans += right -    A[i + 1] -= right -    B[i] -= right -print(ans) +n = int(eval(input())) +a = list(map(int, input().split())) +b = list(map(int, input().split())) +killed = 0 +for i in range(n): +    now_kill = min(a[i], b[i]) +    killed += now_kill +    # a[i] -= now_kill +    b[i] -= now_kill +    if b[i] == 0: +        continue +    now_kill = min(a[i + 1], b[i]) +    killed += now_kill +    a[i + 1] -= now_kill +    # b[i] -= now_kill +print(killed)