n = int(input())

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

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

ret = 0

for i in range(n):

    e = min(a[i], b[i])

    ret += e

    a[i] -= e

    b[i] -= e

    e = min(a[i + 1], b[i])

    ret += e

    a[i + 1] -= e

    b[i] -= e



print(ret)

N = int(eval(input()))

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

B = [int(s) for s in input().split(' ')] + [0]

m = 0

pa = 0

for a, b in zip(A, B):

    m1 = 0

    if pa > 0:

        m1 = min(pa, a)

        a -= m1

    m2 = min(a, b)

    pa = b - m2

    m += m1 + m2



print(m)

n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
ret = 0
for i in range(n):
    e = min(a[i], b[i])
    ret += e
    a[i] -= e
    b[i] -= e
    e = min(a[i + 1], b[i])
    ret += e
    a[i + 1] -= e
    b[i] -= e
print(ret)

N = int(eval(input()))
A = [int(s) for s in input().split(" ")]
B = [int(s) for s in input().split(" ")] + [0]
m = 0
pa = 0
for a, b in zip(A, B):
    m1 = 0
    if pa > 0:
        m1 = min(pa, a)
        a -= m1
    m2 = min(a, b)
    pa = b - m2
    m += m1 + m2
print(m)

-n = int(input()) -a = [int(i) for i in input().split(" ")] -b = [int(i) for i in input().split(" ")] -ret = 0 -for i in range(n): -    e = min(a[i], b[i]) -    ret += e -    a[i] -= e -    b[i] -= e -    e = min(a[i + 1], b[i]) -    ret += e -    a[i + 1] -= e -    b[i] -= e -print(ret) +N = int(eval(input())) +A = [int(s) for s in input().split(" ")] +B = [int(s) for s in input().split(" ")] + [0] +m = 0 +pa = 0 +for a, b in zip(A, B): +    m1 = 0 +    if pa > 0: +        m1 = min(pa, a) +        a -= m1 +    m2 = min(a, b) +    pa = b - m2 +    m += m1 + m2 +print(m)