n = int(eval(input()))

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

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



total = 0

for i in range(n):

    if b[i] > a[i]:

        total += a[i]

        if b[i]-a[i] > a[i+1]:

            total += a[i+1]

            a[i+1] = 0

        else:

            total += b[i] - a[i]

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

    else:

        total += b[i]

print(total)
N = int(eval(input()))

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

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



ans = 0

carry = 0

for a, b in zip(A, B):

    a2 = max(0, a - carry)



    if a2 < b:

        ans += a

        carry = b - a2

    else:

        ans += carry + b

        carry = 0



ans += min(carry, A[-1])

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

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
carry = 0
for a, b in zip(A, B):
    a2 = max(0, a - carry)
    if a2 < b:
        ans += a
        carry = b - a2
    else:
        ans += carry + b
        carry = 0
ans += min(carry, A[-1])
print(ans)

-n = int(eval(input())) -a = list(map(int, input().split())) -b = list(map(int, input().split())) -total = 0 -for i in range(n): -    if b[i] > a[i]: -        total += a[i] -        if b[i] - a[i] > a[i + 1]: -            total += a[i + 1] -            a[i + 1] = 0 -        else: -            total += b[i] - a[i] -            a[i + 1] -= b[i] - a[i] +N = int(eval(input())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) +ans = 0 +carry = 0 +for a, b in zip(A, B): +    a2 = max(0, a - carry) +    if a2 < b: +        ans += a +        carry = b - a2 -        total += b[i] -print(total) +        ans += carry + b +        carry = 0 +ans += min(carry, A[-1]) +print(ans)