N=int(eval(input()))

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

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

C=[B[i] for i in range(N)]

X=[A[i] for i in range(N+1)]

for i in range(N):

    if X[i]<C[i]:

        C[i]-=X[i]

        X[i]=0

        X[i+1]=max(0,X[i+1]-C[i])

    else:

        X[i]-=C[i]

        C[i]=0

print((sum(A)-sum(X)))
N=int(eval(input()))

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

C=[int(i) for i in input().split()]

X=[A[i] for i in range(N+1)]

for i in range(N):

    if X[i]<C[i]:

        C[i]-=X[i]

        X[i]=0

        X[i+1]=max(0,X[i+1]-C[i])

    else:

        X[i]-=C[i]

        C[i]=0

print((sum(A)-sum(X)))

N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [B[i] for i in range(N)]
X = [A[i] for i in range(N + 1)]
for i in range(N):
    if X[i] < C[i]:
        C[i] -= X[i]
        X[i] = 0
        X[i + 1] = max(0, X[i + 1] - C[i])
    else:
        X[i] -= C[i]
        C[i] = 0
print((sum(A) - sum(X)))

N = int(eval(input()))
A = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
X = [A[i] for i in range(N + 1)]
for i in range(N):
    if X[i] < C[i]:
        C[i] -= X[i]
        X[i] = 0
        X[i + 1] = max(0, X[i + 1] - C[i])
    else:
        X[i] -= C[i]
        C[i] = 0
print((sum(A) - sum(X)))

-B = [int(i) for i in input().split()] -C = [B[i] for i in range(N)] +C = [int(i) for i in input().split()]