inf = 10 ** 18

P = 10 ** 9 + 7



N = int(eval(input()))

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

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



A_all = sum(A)



xi = min(A[0], B[0])

A[0] -= xi

B[0] -= xi

for i in range(N):

    yi = min(B[i], A[i + 1])

    A[1 + i] -= yi

    B[i] -= yi

    #

    if i < N - 1:

        xi = min(A[1 + i], B[1 + i])

        A[1 + i] -= xi

        B[1 + i] -= xi

    #

    # print("#", A, B, A_all - sum(A))

    

A_r = list(reversed(A))

B_r = list(reversed(B))





xi = min(A_r[0], B_r[0])

A_r[0] -= xi

B_r[0] -= xi

for i in range(N):

    yi = min(B_r[i], A_r[i + 1])

    A_r[1 + i] -= yi

    B_r[i] -= yi

    #

    if i < N - 1:

        xi = min(A_r[1 + i], B_r[1 + i])

        A_r[1 + i] -= xi

        B_r[1 + i] -= xi

    #

    # print("#", A, B, A_all - sum(A))



print((A_all - 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):

    left = min(A[i], B[i])

    A[i] -= left

    B[i] -= left

    ans += left

    right = min(A[i + 1], B[i])

    A[i + 1] -= right

    B[i] -= right

    ans += right



print(ans)
inf = 10**18
P = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_all = sum(A)
xi = min(A[0], B[0])
A[0] -= xi
B[0] -= xi
for i in range(N):
    yi = min(B[i], A[i + 1])
    A[1 + i] -= yi
    B[i] -= yi
    #
    if i < N - 1:
        xi = min(A[1 + i], B[1 + i])
        A[1 + i] -= xi
        B[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))
A_r = list(reversed(A))
B_r = list(reversed(B))
xi = min(A_r[0], B_r[0])
A_r[0] -= xi
B_r[0] -= xi
for i in range(N):
    yi = min(B_r[i], A_r[i + 1])
    A_r[1 + i] -= yi
    B_r[i] -= yi
    #
    if i < N - 1:
        xi = min(A_r[1 + i], B_r[1 + i])
        A_r[1 + i] -= xi
        B_r[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))
print((A_all - 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):
    left = min(A[i], B[i])
    A[i] -= left
    B[i] -= left
    ans += left
    right = min(A[i + 1], B[i])
    A[i + 1] -= right
    B[i] -= right
    ans += right
print(ans)

-inf = 10**18 -P = 10**9 + 7 -A_all = sum(A) -xi = min(A[0], B[0]) -A[0] -= xi -B[0] -= xi +ans = 0 -    yi = min(B[i], A[i + 1]) -    A[1 + i] -= yi -    B[i] -= yi -    # -    if i < N - 1: -        xi = min(A[1 + i], B[1 + i]) -        A[1 + i] -= xi -        B[1 + i] -= xi -    # -    # print("#", A, B, A_all - sum(A)) -A_r = list(reversed(A)) -B_r = list(reversed(B)) -xi = min(A_r[0], B_r[0]) -A_r[0] -= xi -B_r[0] -= xi -for i in range(N): -    yi = min(B_r[i], A_r[i + 1]) -    A_r[1 + i] -= yi -    B_r[i] -= yi -    # -    if i < N - 1: -        xi = min(A_r[1 + i], B_r[1 + i]) -        A_r[1 + i] -= xi -        B_r[1 + i] -= xi -    # -    # print("#", A, B, A_all - sum(A)) -print((A_all - sum(A))) +    left = min(A[i], B[i]) +    A[i] -= left +    B[i] -= left +    ans += left +    right = min(A[i + 1], B[i]) +    A[i + 1] -= right +    B[i] -= right +    ans += right +print(ans)