N = int(eval(input()))

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

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

a.reverse()

b.reverse()

ans = 0

capacity = 0

for i in range(N):

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

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

ans += min(a[-1], capacity)

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()))
b = list(map(int, input().split()))
a.reverse()
b.reverse()
ans = 0
capacity = 0
for i in range(N):
    ans += min(b[i] + capacity, a[i])
    capacity = max(b[i] - max(a[i] - capacity, 0), 0)
ans += min(a[-1], capacity)
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())) +n = int(eval(input())) -a.reverse() -b.reverse() +a = a[::-1] +b = b[::-1] -capacity = 0 -for i in range(N): -    ans += min(b[i] + capacity, a[i]) -    capacity = max(b[i] - max(a[i] - capacity, 0), 0) -ans += min(a[-1], capacity) +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)