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]

    else:

        ans += b[i]

        b[i] = 0

    if b[i] > 0:

        if a[i+1] > b[i]:

            ans += b[i]

            a[i+1] -= b[i]

        else:

            ans += a[i+1]

            a[i+1] = 0

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

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

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

cnt = 0

for i in range(n):

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

        cnt += A[i]

        B[i] -= A[i]

    else:

        cnt += B[i]

        B[i] = 0

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

        cnt += A[i+1]

        A[i+1] = 0

    else:

        cnt += B[i]

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

print(cnt)
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]
    else:
        ans += b[i]
        b[i] = 0
    if b[i] > 0:
        if a[i + 1] > b[i]:
            ans += b[i]
            a[i + 1] -= b[i]
        else:
            ans += a[i + 1]
            a[i + 1] = 0
print(ans)

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

-a = list(map(int, input().split())) -b = list(map(int, input().split())) -ans = 0 +A = list(map(int, input().split())) +B = list(map(int, input().split())) +cnt = 0 -    if a[i] <= b[i]: -        ans += a[i] -        b[i] -= a[i] +    if A[i] <= B[i]: +        cnt += A[i] +        B[i] -= A[i] -        ans += b[i] -        b[i] = 0 -    if b[i] > 0: -        if a[i + 1] > b[i]: -            ans += b[i] -            a[i + 1] -= b[i] -        else: -            ans += a[i + 1] -            a[i + 1] = 0 -print(ans) +        cnt += B[i] +        B[i] = 0 +    if A[i + 1] <= B[i]: +        cnt += A[i + 1] +        A[i + 1] = 0 +    else: +        cnt += B[i] +        A[i + 1] -= B[i] +print(cnt)