N = int(eval(input()))

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

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



sum_m = 0

killed = 0

rest = 0

for i in range(0, N):

  killed = min(H[i]+rest, M[i])

  rest = min(H[i]+rest-killed, H[i])

  sum_m += killed

sum_m += min(rest, M[-1])

print(sum_m)

N = int(eval(input()))

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

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



sum_m = 0

rest = 0

for i in range(N):

  if M[i] >= H[i]+rest:

    sum_m += H[i]+rest

    rest = 0

  else:

    sum_m += M[i]

    rest = min(H[i], H[i]+rest-M[i])

sum_m += min(rest, M[-1])



print(sum_m)

N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
    killed = min(H[i] + rest, M[i])
    rest = min(H[i] + rest - killed, H[i])
    sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)

N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
rest = 0
for i in range(N):
    if M[i] >= H[i] + rest:
        sum_m += H[i] + rest
        rest = 0
    else:
        sum_m += M[i]
        rest = min(H[i], H[i] + rest - M[i])
sum_m += min(rest, M[-1])
print(sum_m)

-killed = 0 -for i in range(0, N): -    killed = min(H[i] + rest, M[i]) -    rest = min(H[i] + rest - killed, H[i]) -    sum_m += killed +for i in range(N): +    if M[i] >= H[i] + rest: +        sum_m += H[i] + rest +        rest = 0 +    else: +        sum_m += M[i] +        rest = min(H[i], H[i] + rest - M[i])