R = lambda: list(map(int, input().split()))

eval(input())

a = list(R())

r = y = 0

for u, v, w in zip(R(), a, a[1:]):

    x = min(v - y, u)

    y = min(w, u - x)

    r += x + y

print(r)
R = lambda: list(map(int, input().split()))

eval(input())

a = list(R())

def f():

    y = 0

    for u, v, w in zip(R(), a, a[1:]):

        x = min(v - y, u)

        y = min(w, u - x)

        yield x + y

print((sum(f())))

R = lambda: list(map(int, input().split()))
eval(input())
a = list(R())
r = y = 0
for u, v, w in zip(R(), a, a[1:]):
    x = min(v - y, u)
    y = min(w, u - x)
    r += x + y
print(r)

R = lambda: list(map(int, input().split()))
eval(input())
a = list(R())


def f():
    y = 0
    for u, v, w in zip(R(), a, a[1:]):
        x = min(v - y, u)
        y = min(w, u - x)
        yield x + y


print((sum(f())))

-r = y = 0 -for u, v, w in zip(R(), a, a[1:]): -    x = min(v - y, u) -    y = min(w, u - x) -    r += x + y -print(r) + + +def f(): +    y = 0 +    for u, v, w in zip(R(), a, a[1:]): +        x = min(v - y, u) +        y = min(w, u - x) +        yield x + y + + +print((sum(f())))