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 = max(0, 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

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
killed = 0
rest = 0
for i in range(0, N):
    killed = min(H[i] + rest, M[i])
    rest = max(0, 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
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)

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