n=int(eval(input()))

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

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

monster=sum(b)

for i in range(n+1):

  if i==0:

    k=min(a[0],b[0])

    a[0]-=k

    b[0]-=k

  elif i==n:

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

    a[i]-=k

    b[i-1]-=k

  else:

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

    a[i]-=k

    if b[i-1]<k:

      b[i]-=k-b[i-1]

      b[i-1]=0

    else:

      b[i-1]-=k

print((monster-sum(b)))
n=int(eval(input()))

a=[0]+list(map(int,input().split()))

b=[0]+list(map(int,input().split()))+[0]

monster=sum(b)

for i in range(1,n+2):

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

  a[i]-=k

  if b[i-1]<k:

    b[i]-=k-b[i-1]

    b[i-1]=0

  else:

    b[i-1]-=k

print((monster-sum(b)))
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
monster = sum(b)
for i in range(n + 1):
    if i == 0:
        k = min(a[0], b[0])
        a[0] -= k
        b[0] -= k
    elif i == n:
        k = min(a[i], b[i - 1])
        a[i] -= k
        b[i - 1] -= k
    else:
        k = min(a[i], b[i] + b[i - 1])
        a[i] -= k
        if b[i - 1] < k:
            b[i] -= k - b[i - 1]
            b[i - 1] = 0
        else:
            b[i - 1] -= k
print((monster - sum(b)))

n = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split())) + [0]
monster = sum(b)
for i in range(1, n + 2):
    k = min(a[i], b[i] + b[i - 1])
    a[i] -= k
    if b[i - 1] < k:
        b[i] -= k - b[i - 1]
        b[i - 1] = 0
    else:
        b[i - 1] -= k
print((monster - sum(b)))

-a = list(map(int, input().split())) -b = list(map(int, input().split())) +a = [0] + list(map(int, input().split())) +b = [0] + list(map(int, input().split())) + [0] -for i in range(n + 1): -    if i == 0: -        k = min(a[0], b[0]) -        a[0] -= k -        b[0] -= k -    elif i == n: -        k = min(a[i], b[i - 1]) -        a[i] -= k +for i in range(1, n + 2): +    k = min(a[i], b[i] + b[i - 1]) +    a[i] -= k +    if b[i - 1] < k: +        b[i] -= k - b[i - 1] +        b[i - 1] = 0 +    else: -    else: -        k = min(a[i], b[i] + b[i - 1]) -        a[i] -= k -        if b[i - 1] < k: -            b[i] -= k - b[i - 1] -            b[i - 1] = 0 -        else: -            b[i - 1] -= k