n = int(eval(input()))

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

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

res = 0

for i in range(n):

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

    a[i] -= t1

    b[i] -= t1

    res += t1

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

    a[i+1] -= t2

    b[i] -= t2

    res += t2

print(res)

n=int(eval(input()))

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

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

ans=0

for i in range(n):

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

    ans+=m

    a[i]-=m

    b[i]-=m

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

    a[i+1]-=m

    b[i]-=m

    ans+=m

print(ans)

        

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
    t1 = min(a[i], b[i])
    a[i] -= t1
    b[i] -= t1
    res += t1
    t2 = min(a[i + 1], b[i])
    a[i + 1] -= t2
    b[i] -= t2
    res += t2
print(res)

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

-a = list(map(int, input().split())) -b = list(map(int, input().split())) -res = 0 +a = [int(i) for i in input().split()] +b = [int(i) for i in input().split()] +ans = 0 -    t1 = min(a[i], b[i]) -    a[i] -= t1 -    b[i] -= t1 -    res += t1 -    t2 = min(a[i + 1], b[i]) -    a[i + 1] -= t2 -    b[i] -= t2 -    res += t2 -print(res) +    m = min(a[i], b[i]) +    ans += m +    a[i] -= m +    b[i] -= m +    m = min(a[i + 1], b[i]) +    a[i + 1] -= m +    b[i] -= m +    ans += m +print(ans)