N = int(eval(input()))

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

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

cnt = 0

for i in range(N):

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

    a = A[i]

    A[i] = max(a-B[i],0)

    B[i] = max(B[i]-a,0)

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

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

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

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

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

tot = 0

c = 0

for i in range(N):

    a = A[i]

    b = B[i]

    if a>=c:

        a -= c

        tot += c

        if a>=b:

            tot += b

            c = 0

        else:

            tot += a

            c = b-a

    else:

        tot += a

        c = b

a = A[N]

tot += min(a,c)

print(tot)
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for i in range(N):
    cnt += min(A[i], B[i])
    a = A[i]
    A[i] = max(a - B[i], 0)
    B[i] = max(B[i] - a, 0)
    cnt += min(A[i + 1], B[i])
    A[i + 1] = max(A[i + 1] - B[i], 0)
print(cnt)

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

-cnt = 0 +tot = 0 +c = 0 -    cnt += min(A[i], B[i]) -    A[i] = max(a - B[i], 0) -    B[i] = max(B[i] - a, 0) -    cnt += min(A[i + 1], B[i]) -    A[i + 1] = max(A[i + 1] - B[i], 0) -print(cnt) +    b = B[i] +    if a >= c: +        a -= c +        tot += c +        if a >= b: +            tot += b +            c = 0 +        else: +            tot += a +            c = b - a +    else: +        tot += a +        c = b +a = A[N] +tot += min(a, c) +print(tot)