n = int(eval(input()))

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

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



a = a[::-1]

b = b[::-1]

ans = 0

for i, bi in enumerate(b):

    ans += min(a[i], b[i])

    remain = max(0, b[i] - a[i])

    ans += min(a[i + 1], remain)

    a[i + 1] = max(0, a[i + 1] - remain)

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

A = list(map(int, input().split()))[::-1]

B = list(map(int, input().split()))[::-1]

ans = 0



for i, b in enumerate(B):

    ans += min(A[i], b)

    remain = max(0, b - A[i])

    ans += min(A[i + 1], remain)

    A[i + 1] = max(0, A[i + 1] - remain)



print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = a[::-1]
b = b[::-1]
ans = 0
for i, bi in enumerate(b):
    ans += min(a[i], b[i])
    remain = max(0, b[i] - a[i])
    ans += min(a[i + 1], remain)
    a[i + 1] = max(0, a[i + 1] - remain)
print(ans)

n = int(eval(input()))
A = list(map(int, input().split()))[::-1]
B = list(map(int, input().split()))[::-1]
ans = 0
for i, b in enumerate(B):
    ans += min(A[i], b)
    remain = max(0, b - A[i])
    ans += min(A[i + 1], remain)
    A[i + 1] = max(0, A[i + 1] - remain)
print(ans)

-a = list(map(int, input().split())) -b = list(map(int, input().split())) -a = a[::-1] -b = b[::-1] +A = list(map(int, input().split()))[::-1] +B = list(map(int, input().split()))[::-1] -for i, bi in enumerate(b): -    ans += min(a[i], b[i]) -    remain = max(0, b[i] - a[i]) -    ans += min(a[i + 1], remain) -    a[i + 1] = max(0, a[i + 1] - remain) +for i, b in enumerate(B): +    ans += min(A[i], b) +    remain = max(0, b - A[i]) +    ans += min(A[i + 1], remain) +    A[i + 1] = max(0, A[i + 1] - remain)