N = int(eval(input()))

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

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

ans = 0



for i in range(N):

    ans += min(A[i], B[i])

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

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

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

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

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

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



ans = sum(A)



for i in range(N):

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

    A[i] -= n

    B[i] -= n

    

    if B[i] > 0: A[i+1] = max(0, A[i+1]-B[i])



print((ans - 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):
    ans += min(A[i], B[i])
    B[i] -= min(A[i], B[i])
    ans += min(A[i + 1], B[i])
    A[i + 1] -= min(A[i + 1], B[i])
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = sum(A)
for i in range(N):
    n = min(A[i], B[i])
    A[i] -= n
    B[i] -= n
    if B[i] > 0:
        A[i + 1] = max(0, A[i + 1] - B[i])
print((ans - sum(A)))

-ans = 0 +ans = sum(A) -    ans += min(A[i], B[i]) -    B[i] -= min(A[i], B[i]) -    ans += min(A[i + 1], B[i]) -    A[i + 1] -= min(A[i + 1], B[i]) -print(ans) +    n = min(A[i], B[i]) +    A[i] -= n +    B[i] -= n +    if B[i] > 0: +        A[i + 1] = max(0, A[i + 1] - B[i]) +print((ans - sum(A)))