N = int(eval(input()))

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

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

z = 0



for i in range(N):

  if B[i]<=A[i]:

    z+=B[i]

  elif A[i]<B[i]<=A[i]+A[i+1]:

    z+=B[i]

    A[i+1]-=B[i]-A[i]

  else:

    z+=A[i]+A[i+1]

    A[i+1]=0



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

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

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

ans = 0



for n in range(N):

  if B[n]<=A[n]:

    ans+=B[n]

  elif B[n]<=A[n]+A[n+1]:

    ans+=B[n]

    A[n+1]-=B[n]-A[n]

  else:

    ans+=A[n]+A[n+1]

    A[n+1] = 0



print(ans)
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
z = 0
for i in range(N):
    if B[i] <= A[i]:
        z += B[i]
    elif A[i] < B[i] <= A[i] + A[i + 1]:
        z += B[i]
        A[i + 1] -= B[i] - A[i]
    else:
        z += A[i] + A[i + 1]
        A[i + 1] = 0
print(z)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for n in range(N):
    if B[n] <= A[n]:
        ans += B[n]
    elif B[n] <= A[n] + A[n + 1]:
        ans += B[n]
        A[n + 1] -= B[n] - A[n]
    else:
        ans += A[n] + A[n + 1]
        A[n + 1] = 0
print(ans)

-z = 0 -for i in range(N): -    if B[i] <= A[i]: -        z += B[i] -    elif A[i] < B[i] <= A[i] + A[i + 1]: -        z += B[i] -        A[i + 1] -= B[i] - A[i] +ans = 0 +for n in range(N): +    if B[n] <= A[n]: +        ans += B[n] +    elif B[n] <= A[n] + A[n + 1]: +        ans += B[n] +        A[n + 1] -= B[n] - A[n] -        z += A[i] + A[i + 1] -        A[i + 1] = 0 -print(z) +        ans += A[n] + A[n + 1] +        A[n + 1] = 0 +print(ans)