N = int(eval(input()))

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

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



ans, surplus = 0, 0

for i in range(N):

    tmp = min(A[i], surplus)

    ans += tmp

    A[i] -= tmp

    if B[i] > A[i]:

        ans += A[i]

        surplus = B[i] - A[i]

    else:

        ans += B[i]

        surplus = 0

tmp = min(A[N], surplus)

ans += tmp

print(ans)

N = int(eval(input()))

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

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



ans, mod = 0, 0



for i in range(N):



    if mod > A[i]:

        ans += A[i]

        A[i] = 0

    else:

        ans += mod

        A[i] -= mod

        mod = 0



    if B[i] > A[i]:

        ans += A[i]

        mod = B[i] - A[i]

    else:

        ans += B[i]

        mod = 0



ans += min(mod, A[N])



print(ans)

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

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

-ans, surplus = 0, 0 +ans, mod = 0, 0 -    tmp = min(A[i], surplus) -    ans += tmp -    A[i] -= tmp +    if mod > A[i]: +        ans += A[i] +        A[i] = 0 +    else: +        ans += mod +        A[i] -= mod +        mod = 0 -        surplus = B[i] - A[i] +        mod = B[i] - A[i] -        surplus = 0 -tmp = min(A[N], surplus) -ans += tmp +        mod = 0 +ans += min(mod, A[N])