N=int(eval(input()))

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

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

A=a.copy()

for i in reversed(list(range(N))):

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

    if A[i]+A[i+1]-B[i]>=0:

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

      A[i+1]=0

    else:

      A[i]=0

      A[i+1]=0

  else:

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

print((sum(a)-sum(A)))

n=int(eval(input()))

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

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

ans=0

for i in range(n):

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

        a[i]=a[i]-b[i]

        ans+=b[i]

    elif a[i+1]-(b[i]-a[i])>=0:

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

        a[i]=0

        ans+=b[i]

    else:

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

        a[i+1]=0

        a[i]=0

print(ans)
N = int(eval(input()))
a = list(map(int, input().split()))
B = list(map(int, input().split()))
A = a.copy()
for i in reversed(list(range(N))):
    if A[i + 1] - B[i] <= 0:
        if A[i] + A[i + 1] - B[i] >= 0:
            A[i] = A[i] + A[i + 1] - B[i]
            A[i + 1] = 0
        else:
            A[i] = 0
            A[i + 1] = 0
    else:
        A[i + 1] = A[i + 1] - B[i]
print((sum(a) - sum(A)))

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

-N = int(eval(input())) +n = int(eval(input())) -B = list(map(int, input().split())) -A = a.copy() -for i in reversed(list(range(N))): -    if A[i + 1] - B[i] <= 0: -        if A[i] + A[i + 1] - B[i] >= 0: -            A[i] = A[i] + A[i + 1] - B[i] -            A[i + 1] = 0 -        else: -            A[i] = 0 -            A[i + 1] = 0 +b = list(map(int, input().split())) +ans = 0 +for i in range(n): +    if a[i] >= b[i]: +        a[i] = a[i] - b[i] +        ans += b[i] +    elif a[i + 1] - (b[i] - a[i]) >= 0: +        a[i + 1] = a[i + 1] - (b[i] - a[i]) +        a[i] = 0 +        ans += b[i] -        A[i + 1] = A[i + 1] - B[i] -print((sum(a) - sum(A))) +        ans += a[i] + a[i + 1] +        a[i + 1] = 0 +        a[i] = 0 +print(ans)