N=int(eval(input()))

A=[int(x) for x in input().rstrip().split()]

B=[int(x) for x in input().rstrip().split()]

ans=0

now=A[0]

for i in range(N):

  if B[i]<=A[i]:

    ans+=B[i]

  else:

    if A[i]+A[i+1]<=B[i]:

      ans+=A[i]+A[i+1]

      A[i+1]=0

    else:

      ans+=B[i]

      A[i+1]=A[i+1]-(B[i]-A[i])

print(ans)



n=int(eval(input()))

a=[int(x) for x in input().rstrip().split()]

b=[int(x) for x in input().rstrip().split()]

ans=0

for i in range(len(b)):

  if a[i]+a[i+1]<=b[i]:

    ans+=a[i]+a[i+1]

    a[i]=0

    a[i+1]=0

  

  elif a[i]<=b[i]:

    ans+=a[i]

    ans+=(b[i]-a[i])

    a[i+1]=a[i+1]-(b[i]-a[i])

  else:

    a[i]-=b[i]

    ans+=b[i]

print(ans)
N = int(eval(input()))
A = [int(x) for x in input().rstrip().split()]
B = [int(x) for x in input().rstrip().split()]
ans = 0
now = A[0]
for i in range(N):
    if B[i] <= A[i]:
        ans += B[i]
    else:
        if A[i] + A[i + 1] <= B[i]:
            ans += A[i] + A[i + 1]
            A[i + 1] = 0
        else:
            ans += B[i]
            A[i + 1] = A[i + 1] - (B[i] - A[i])
print(ans)

n = int(eval(input()))
a = [int(x) for x in input().rstrip().split()]
b = [int(x) for x in input().rstrip().split()]
ans = 0
for i in range(len(b)):
    if a[i] + a[i + 1] <= b[i]:
        ans += a[i] + a[i + 1]
        a[i] = 0
        a[i + 1] = 0
    elif a[i] <= b[i]:
        ans += a[i]
        ans += b[i] - a[i]
        a[i + 1] = a[i + 1] - (b[i] - a[i])
    else:
        a[i] -= b[i]
        ans += b[i]
print(ans)

-N = int(eval(input())) -A = [int(x) for x in input().rstrip().split()] -B = [int(x) for x in input().rstrip().split()] +n = int(eval(input())) +a = [int(x) for x in input().rstrip().split()] +b = [int(x) for x in input().rstrip().split()] -now = A[0] -for i in range(N): -    if B[i] <= A[i]: -        ans += B[i] +for i in range(len(b)): +    if a[i] + a[i + 1] <= b[i]: +        ans += a[i] + a[i + 1] +        a[i] = 0 +        a[i + 1] = 0 +    elif a[i] <= b[i]: +        ans += a[i] +        ans += b[i] - a[i] +        a[i + 1] = a[i + 1] - (b[i] - a[i]) -        if A[i] + A[i + 1] <= B[i]: -            ans += A[i] + A[i + 1] -            A[i + 1] = 0 -        else: -            ans += B[i] -            A[i + 1] = A[i + 1] - (B[i] - A[i]) +        a[i] -= b[i] +        ans += b[i]