f=lambda:list(map(int,input().split()))

n=f()[0];l=f();c=0;t=l.pop(0)

for a,b in zip(l,f()):

  s=min(t+a,b);t=min(max(t+a-s,0),a);c+=s

print(c)
f=lambda:list(map(int,input().split()))

eval(input())

p,*A=f()

B=f()

s=0

for a,b in zip(A,B):

  t=min(b,a+p)

  p=a-max(0,t-p)

  s+=t

print(s)
f = lambda: list(map(int, input().split()))
n = f()[0]
l = f()
c = 0
t = l.pop(0)
for a, b in zip(l, f()):
    s = min(t + a, b)
    t = min(max(t + a - s, 0), a)
    c += s
print(c)

f = lambda: list(map(int, input().split()))
eval(input())
p, *A = f()
B = f()
s = 0
for a, b in zip(A, B):
    t = min(b, a + p)
    p = a - max(0, t - p)
    s += t
print(s)

-n = f()[0] -l = f() -c = 0 -t = l.pop(0) -for a, b in zip(l, f()): -    s = min(t + a, b) -    t = min(max(t + a - s, 0), a) -    c += s -print(c) +eval(input()) +p, *A = f() +B = f() +s = 0 +for a, b in zip(A, B): +    t = min(b, a + p) +    p = a - max(0, t - p) +    s += t +print(s)