import collections

n = int(input())

cities = collections.deque(list(map(int, input().split(' '))))

q = collections.deque(list(map(int, input().split(' '))))

res = 0

p = 0

while(q):

	w = q.pop()

	if cities[-1]:

		m = min(w, cities[-1])

		cities[-1]-=m

		w -= m

		res += m

	cities.pop()

	if cities[-1]:

		m = min(w, cities[-1])

		cities[-1]-=m

		w -= m

		res += m

print(res)
import collections

n = int(input())

cities,q = collections.deque(list(map(int, input().split(' ')))), collections.deque(list(map(int, input().split(' '))))

res = 0

while(q):

	u = q.pop()

	for _ in range(2):

		c = cities.pop()

		m = min(u, c)

		c -=m

		u -= m

		res += m

	cities.append(c)

print(res)
import collections

n = int(input())
cities = collections.deque(list(map(int, input().split(" "))))
q = collections.deque(list(map(int, input().split(" "))))
res = 0
p = 0
while q:
    w = q.pop()
    if cities[-1]:
        m = min(w, cities[-1])
        cities[-1] -= m
        w -= m
        res += m
    cities.pop()
    if cities[-1]:
        m = min(w, cities[-1])
        cities[-1] -= m
        w -= m
        res += m
print(res)

import collections

n = int(input())
cities, q = collections.deque(list(map(int, input().split(" ")))), collections.deque(
    list(map(int, input().split(" ")))
)
res = 0
while q:
    u = q.pop()
    for _ in range(2):
        c = cities.pop()
        m = min(u, c)
        c -= m
        u -= m
        res += m
    cities.append(c)
print(res)

-cities = collections.deque(list(map(int, input().split(" ")))) -q = collections.deque(list(map(int, input().split(" ")))) +cities, q = collections.deque(list(map(int, input().split(" ")))), collections.deque( +    list(map(int, input().split(" "))) +) -p = 0 -    w = q.pop() -    if cities[-1]: -        m = min(w, cities[-1]) -        cities[-1] -= m -        w -= m +    u = q.pop() +    for _ in range(2): +        c = cities.pop() +        m = min(u, c) +        c -= m +        u -= m -    cities.pop() -    if cities[-1]: -        m = min(w, cities[-1]) -        cities[-1] -= m -        w -= m -        res += m +    cities.append(c)