N = int(eval(input()))

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

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

s = 0

for i in range(N):

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

    s = s + A[i] + A[i+1]

    A[i]=0

    A[i+1] = 0

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

    s = s + B[i]

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

    A[i] = 0

  else:

    s = s + B[i]

    A[i] = B[i] - A[i]

    

print(s)

  
N = int(eval(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 += 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]

    else:

        ans += B[i]

        

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

N = int(eval(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 += 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]
    else:
        ans += B[i]
print(ans)

-s = 0 +ans = 0 -    if A[i] + A[i + 1] <= B[i]: -        s = s + A[i] + A[i + 1] -        A[i] = 0 -        A[i + 1] = 0 -    elif A[i] <= B[i] and A[i] + A[i + 1] > B[i]: -        s = s + B[i] -        A[i + 1] = A[i + 1] + A[i] - B[i] -        A[i] = 0 +    if A[i] < B[i]: +        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] -        s = s + B[i] -        A[i] = B[i] - A[i] -print(s) +        ans += B[i] +print(ans)