n = int(eval(input()))

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

num = sum(aa)

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

for i in range(n):

    c = min(aa[i], bb[i])

    aa[i] -= c

    aa[i + 1] -= min(aa[i + 1], bb[i] - c)

print((num - sum(aa)))
n=int(eval(input()))

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

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

b.append(0) #n+1番目を作っとく

num=0

c=0

for i in range(n):

    if a[i]<=c:

        num+=a[i]

        c=b[i]

    else:

        a[i]-=c

        num+=c

        if b[i]>=a[i]:

            num+=a[i]

            c=b[i]-a[i]

        else:

            num+=b[i]

            c=0

        

if b[n]+c>=a[n]:

    num+=a[n]

else:

    num+=b[n]+c

print(num)
n = int(eval(input()))
aa = list(map(int, input().split()))
num = sum(aa)
bb = list(map(int, input().split()))
for i in range(n):
    c = min(aa[i], bb[i])
    aa[i] -= c
    aa[i + 1] -= min(aa[i + 1], bb[i] - c)
print((num - sum(aa)))

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)  # n+1番目を作っとく
num = 0
c = 0
for i in range(n):
    if a[i] <= c:
        num += a[i]
        c = b[i]
    else:
        a[i] -= c
        num += c
        if b[i] >= a[i]:
            num += a[i]
            c = b[i] - a[i]
        else:
            num += b[i]
            c = 0
if b[n] + c >= a[n]:
    num += a[n]
else:
    num += b[n] + c
print(num)

-aa = list(map(int, input().split())) -num = sum(aa) -bb = list(map(int, input().split())) +a = list(map(int, input().split())) +b = list(map(int, input().split())) +b.append(0)  # n+1番目を作っとく +num = 0 +c = 0 -    c = min(aa[i], bb[i]) -    aa[i] -= c -    aa[i + 1] -= min(aa[i + 1], bb[i] - c) -print((num - sum(aa))) +    if a[i] <= c: +        num += a[i] +        c = b[i] +    else: +        a[i] -= c +        num += c +        if b[i] >= a[i]: +            num += a[i] +            c = b[i] - a[i] +        else: +            num += b[i] +            c = 0 +if b[n] + c >= a[n]: +    num += a[n] +else: +    num += b[n] + c +print(num)