import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



N = int(eval(input()))

A = [int(i) for i in input().split()]

B = [int(i) for i in input().split()]

before = sum(A)



for i in range(N):

    nokori = B[i]

    for j in range(i,i+2):

        if nokori >= A[j]:

            nokori -= A[j]

            A[j] = 0

        else:

            A[j] -= nokori

            nokori = 0

after = sum(A)



print((before - after))
N = int(eval(input()))

A = [int(i) for i in input().split()]

B = [int(i) for i in input().split()]



cnt = 0

for i in range(N):

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

        cnt += A[i]

        B[i] -= A[i]

    else:

        cnt += B[i]

        B[i] = 0

    if B[i] == 0:

        continue

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

        cnt += A[i+1]

        A[i+1] = 0

    else:

        cnt += B[i]

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



print(cnt)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
before = sum(A)
for i in range(N):
    nokori = B[i]
    for j in range(i, i + 2):
        if nokori >= A[j]:
            nokori -= A[j]
            A[j] = 0
        else:
            A[j] -= nokori
            nokori = 0
after = sum(A)
print((before - after))

N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
cnt = 0
for i in range(N):
    if B[i] >= A[i]:
        cnt += A[i]
        B[i] -= A[i]
    else:
        cnt += B[i]
        B[i] = 0
    if B[i] == 0:
        continue
    if B[i] >= A[i + 1]:
        cnt += A[i + 1]
        A[i + 1] = 0
    else:
        cnt += B[i]
        A[i + 1] -= B[i]
print(cnt)

-import sys - -input = sys.stdin.readline -sys.setrecursionlimit(10**7) -before = sum(A) +cnt = 0 -    nokori = B[i] -    for j in range(i, i + 2): -        if nokori >= A[j]: -            nokori -= A[j] -            A[j] = 0 -        else: -            A[j] -= nokori -            nokori = 0 -after = sum(A) -print((before - after)) +    if B[i] >= A[i]: +        cnt += A[i] +        B[i] -= A[i] +    else: +        cnt += B[i] +        B[i] = 0 +    if B[i] == 0: +        continue +    if B[i] >= A[i + 1]: +        cnt += A[i + 1] +        A[i + 1] = 0 +    else: +        cnt += B[i] +        A[i + 1] -= B[i] +print(cnt)