N = int(eval(input()))

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

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

start = [0]*(N+1)

attack = 0

enemy = 0



for i in range(N+1):

    start[i] = A[i]



for i in range(N):

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

    A[i] = A[i] - attack

    B[i] = B[i] - attack

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

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

    B[i] = B[i] - attack

    

for i in range(N+1):

    enemy = enemy + (start[i]-A[i])

    

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

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

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



ans = 0



for  i in range(N):

    tmp = 0

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

        A[i] -= B[i]

        ans += B[i]

    else:

        ans += A[i]

        tmp = B[i] - A[i]

        A[i] = 0

        if A[i+1] >= tmp:

            A[i+1] -= tmp

            ans += tmp

        else:

            ans += A[i+1]

            A[i+1] = 0

            

print(ans)    
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
start = [0] * (N + 1)
attack = 0
enemy = 0
for i in range(N + 1):
    start[i] = A[i]
for i in range(N):
    attack = min(A[i], B[i])
    A[i] = A[i] - attack
    B[i] = B[i] - attack
    attack = min(A[i + 1], B[i])
    A[i + 1] = A[i + 1] - attack
    B[i] = B[i] - attack
for i in range(N + 1):
    enemy = enemy + (start[i] - A[i])
print(enemy)

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

-start = [0] * (N + 1) -attack = 0 -enemy = 0 -for i in range(N + 1): -    start[i] = A[i] +ans = 0 -    attack = min(A[i], B[i]) -    A[i] = A[i] - attack -    B[i] = B[i] - attack -    attack = min(A[i + 1], B[i]) -    A[i + 1] = A[i + 1] - attack -    B[i] = B[i] - attack -for i in range(N + 1): -    enemy = enemy + (start[i] - A[i]) -print(enemy) +    tmp = 0 +    if A[i] >= B[i]: +        A[i] -= B[i] +        ans += B[i] +    else: +        ans += A[i] +        tmp = B[i] - A[i] +        A[i] = 0 +        if A[i + 1] >= tmp: +            A[i + 1] -= tmp +            ans += tmp +        else: +            ans += A[i + 1] +            A[i + 1] = 0 +print(ans)