n=int(eval(input()))

ai=[]

for i in map(int,input().split()):

    ai.append(i)

bi=[]

for i in map(int,input().split()):

    bi.append(i)



asum=0

for i in range(n+1):

    asum=asum+ai[i]    



i=0

if ai[i]<=bi[i]:

    bi[i]=bi[i]-ai[i]

    ai[i]=0

else :

    ai[i]=ai[i]-bi[i]

    bi[i]=0

for i in range(1,n,1):

    if ai[i]<=bi[i-1]:

        bi[i-1]=bi[i-1]-ai[i]

        ai[i]=0

    else :

        ai[i]=ai[i]-bi[i-1]

        bi[i-1]=0

    if ai[i]<=bi[i]:

        bi[i]=bi[i]-ai[i]

        ai[i]=0

    else :

        ai[i]=ai[i]-bi[i]

        bi[i]=0

i=n

if ai[i]<=bi[i-1]:

    bi[i-1]=bi[i-1]-ai[i]

    ai[i]=0

else :

    ai[i]=ai[i]-bi[i-1]

    bi[i-1]=0



asum2=0

for i in range(n+1):

    asum2=asum2+ai[i]    



print((asum-asum2))        
n=int(eval(input()))

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

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



fii=min(a[0],b[0])

fij=min(a[1],b[0]-fii)

icnt=fii+fij

for i in range(1,n):

    fii=min(a[i]-fij,b[i])

    fij=min(a[i+1],b[i]-fii)

    icnt+=fij+fii



print(icnt)



n = int(eval(input()))
ai = []
for i in map(int, input().split()):
    ai.append(i)
bi = []
for i in map(int, input().split()):
    bi.append(i)
asum = 0
for i in range(n + 1):
    asum = asum + ai[i]
i = 0
if ai[i] <= bi[i]:
    bi[i] = bi[i] - ai[i]
    ai[i] = 0
else:
    ai[i] = ai[i] - bi[i]
    bi[i] = 0
for i in range(1, n, 1):
    if ai[i] <= bi[i - 1]:
        bi[i - 1] = bi[i - 1] - ai[i]
        ai[i] = 0
    else:
        ai[i] = ai[i] - bi[i - 1]
        bi[i - 1] = 0
    if ai[i] <= bi[i]:
        bi[i] = bi[i] - ai[i]
        ai[i] = 0
    else:
        ai[i] = ai[i] - bi[i]
        bi[i] = 0
i = n
if ai[i] <= bi[i - 1]:
    bi[i - 1] = bi[i - 1] - ai[i]
    ai[i] = 0
else:
    ai[i] = ai[i] - bi[i - 1]
    bi[i - 1] = 0
asum2 = 0
for i in range(n + 1):
    asum2 = asum2 + ai[i]
print((asum - asum2))

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
fii = min(a[0], b[0])
fij = min(a[1], b[0] - fii)
icnt = fii + fij
for i in range(1, n):
    fii = min(a[i] - fij, b[i])
    fij = min(a[i + 1], b[i] - fii)
    icnt += fij + fii
print(icnt)

-ai = [] -for i in map(int, input().split()): -    ai.append(i) -bi = [] -for i in map(int, input().split()): -    bi.append(i) -asum = 0 -for i in range(n + 1): -    asum = asum + ai[i] -i = 0 -if ai[i] <= bi[i]: -    bi[i] = bi[i] - ai[i] -    ai[i] = 0 -else: -    ai[i] = ai[i] - bi[i] -    bi[i] = 0 -for i in range(1, n, 1): -    if ai[i] <= bi[i - 1]: -        bi[i - 1] = bi[i - 1] - ai[i] -        ai[i] = 0 -    else: -        ai[i] = ai[i] - bi[i - 1] -        bi[i - 1] = 0 -    if ai[i] <= bi[i]: -        bi[i] = bi[i] - ai[i] -        ai[i] = 0 -    else: -        ai[i] = ai[i] - bi[i] -        bi[i] = 0 -i = n -if ai[i] <= bi[i - 1]: -    bi[i - 1] = bi[i - 1] - ai[i] -    ai[i] = 0 -else: -    ai[i] = ai[i] - bi[i - 1] -    bi[i - 1] = 0 -asum2 = 0 -for i in range(n + 1): -    asum2 = asum2 + ai[i] -print((asum - asum2)) +a = list(map(int, input().split())) +b = list(map(int, input().split())) +fii = min(a[0], b[0]) +fij = min(a[1], b[0] - fii) +icnt = fii + fij +for i in range(1, n): +    fii = min(a[i] - fij, b[i]) +    fij = min(a[i + 1], b[i] - fii) +    icnt += fij + fii +print(icnt)