n = int(eval(input()))

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

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



num = 0

for i in range(n):

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

       # print(a[i],b[i])

        a[i] -= b[i]

        num += b[i]

        b[i] = 0

        

    elif a[i] < b[i]:

        num += a[i]

        #a[i] = 0

        b[i] -= a[i]

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

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

        

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

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

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

tot = sum(A)

for i in range(n):

    en = A[i] + A[i+1]

    A[i] = max(A[i] -B[i],0)

    if A[i] == 0:

        A[i+1] = max(en - B[i],0)

        #print(A[i],A[i+1])

print((tot-sum(A)))
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num = 0
for i in range(n):
    if a[i] >= b[i]:
        # print(a[i],b[i])
        a[i] -= b[i]
        num += b[i]
        b[i] = 0
    elif a[i] < b[i]:
        num += a[i]
        # a[i] = 0
        b[i] -= a[i]
        num += min(b[i], a[i + 1])
        a[i + 1] = max(a[i + 1] - b[i], 0)
print(num)

n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tot = sum(A)
for i in range(n):
    en = A[i] + A[i + 1]
    A[i] = max(A[i] - B[i], 0)
    if A[i] == 0:
        A[i + 1] = max(en - B[i], 0)
        # print(A[i],A[i+1])
print((tot - sum(A)))

-a = list(map(int, input().split())) -b = list(map(int, input().split())) -num = 0 +A = list(map(int, input().split())) +B = list(map(int, input().split())) +tot = sum(A) -    if a[i] >= b[i]: -        # print(a[i],b[i]) -        a[i] -= b[i] -        num += b[i] -        b[i] = 0 -    elif a[i] < b[i]: -        num += a[i] -        # a[i] = 0 -        b[i] -= a[i] -        num += min(b[i], a[i + 1]) -        a[i + 1] = max(a[i + 1] - b[i], 0) -print(num) +    en = A[i] + A[i + 1] +    A[i] = max(A[i] - B[i], 0) +    if A[i] == 0: +        A[i + 1] = max(en - B[i], 0) +        # print(A[i],A[i+1]) +print((tot - sum(A)))