n = int(eval(input()))

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

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

ans = 0

for i in range(n):

    ans += min(a[i],b[i]) + min(a[i+1],max(b[i]-a[i],0))

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

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

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

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

ans = 0

for i in range(n):

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

    ans += c

    if a[i] < b[i]:

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

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

        

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

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

-    ans += min(a[i], b[i]) + min(a[i + 1], max(b[i] - a[i], 0)) -    a[i + 1] = max(a[i + 1] - max(b[i] - a[i], 0), 0) +    c = min(a[i], b[i]) +    ans += c +    if a[i] < b[i]: +        ans += min(a[i + 1], b[i] - a[i]) +        a[i + 1] = max(a[i + 1] - (b[i] - a[i]), 0)