N = int(eval(input()))

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

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



temp = 0



for i, j in enumerate(A):

    if i == N:

        break

    if j >= B[i]:

        temp += B[i]

        B[i] = 0

        continue

    else:

        temp += j

        B[i] = B[i] - j



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

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

        temp += B[i]

    else:

        temp += A[i + 1]

        A[i + 1] = 0



print(temp)

N = int(eval(input()))

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

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



ans = 0

for i in range(N):

    # i番目の街のモンスターを倒す

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

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

    # i+1番目の街のモンスターを倒す

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

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

print(ans)
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
temp = 0
for i, j in enumerate(A):
    if i == N:
        break
    if j >= B[i]:
        temp += B[i]
        B[i] = 0
        continue
    else:
        temp += j
        B[i] = B[i] - j
    if A[i + 1] >= B[i]:
        A[i + 1] = A[i + 1] - B[i]
        temp += B[i]
    else:
        temp += A[i + 1]
        A[i + 1] = 0
print(temp)

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    # i番目の街のモンスターを倒す
    ans += min(A[i], B[i])
    nb = B[i] - min(A[i], B[i])
    # i+1番目の街のモンスターを倒す
    ans += min(A[i + 1], nb)
    A[i + 1] -= min(A[i + 1], nb)
print(ans)

-temp = 0 -for i, j in enumerate(A): -    if i == N: -        break -    if j >= B[i]: -        temp += B[i] -        B[i] = 0 -        continue -    else: -        temp += j -        B[i] = B[i] - j -    if A[i + 1] >= B[i]: -        A[i + 1] = A[i + 1] - B[i] -        temp += B[i] -    else: -        temp += A[i + 1] -        A[i + 1] = 0 -print(temp) +ans = 0 +for i in range(N): +    # i番目の街のモンスターを倒す +    ans += min(A[i], B[i]) +    nb = B[i] - min(A[i], B[i]) +    # i+1番目の街のモンスターを倒す +    ans += min(A[i + 1], nb) +    A[i + 1] -= min(A[i + 1], nb) +print(ans)