n,*a=list(map(int,open(0).read().split()))

c=0

for i in range(1,n+1):c+=min(a[i-1]+a[i],a[n+i]);a[i]-=max(min(a[n+i]-a[i-1],a[i]),0)

print(c)
n,x,*a=list(map(int,open(0).read().split()))

c=0

for a,b in zip(a,a[n:]):c+=min(x+a,b);x=a-max(min(b-x,a),0)

print(c)
n, *a = list(map(int, open(0).read().split()))
c = 0
for i in range(1, n + 1):
    c += min(a[i - 1] + a[i], a[n + i])
    a[i] -= max(min(a[n + i] - a[i - 1], a[i]), 0)
print(c)

n, x, *a = list(map(int, open(0).read().split()))
c = 0
for a, b in zip(a, a[n:]):
    c += min(x + a, b)
    x = a - max(min(b - x, a), 0)
print(c)

-n, *a = list(map(int, open(0).read().split())) +n, x, *a = list(map(int, open(0).read().split())) -for i in range(1, n + 1): -    c += min(a[i - 1] + a[i], a[n + i]) -    a[i] -= max(min(a[n + i] - a[i - 1], a[i]), 0) +for a, b in zip(a, a[n:]): +    c += min(x + a, b) +    x = a - max(min(b - x, a), 0)