N = int(eval(input()))

Monsters = [int(i) for i in input().split()]

Heroes = [int(i) for i in input().split()]

res = 0

for i in range(N):

    r = Monsters[i] - Heroes[i]

    if r >= 0:

        Monsters[i] -= Heroes[i]

        res += Heroes[i]

    else:

        res += Monsters[i]

        Monsters[i] = 0

        k = Monsters[i+1] + r

        if k >= 0:

            res -= r

            Monsters[i+1] += r

        else:

            res += Monsters[i+1]

            Monsters[i+1] = 0



print(res)
import sys

input=sys.stdin.buffer.readline

import os

from math import*



n=int(eval(input()))

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

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



ans=0

for i in range(n):

	if arr[i]>=brr[i]:

		ans+=brr[i]

	else:

		if arr[i]+arr[i+1]>=brr[i]:

			ans+=brr[i]

			arr[i+1]=arr[i]+arr[i+1]-brr[i]

		else:

			ans+=arr[i]+arr[i+1]

			arr[i+1]=0

print(ans)
N = int(eval(input()))
Monsters = [int(i) for i in input().split()]
Heroes = [int(i) for i in input().split()]
res = 0
for i in range(N):
    r = Monsters[i] - Heroes[i]
    if r >= 0:
        Monsters[i] -= Heroes[i]
        res += Heroes[i]
    else:
        res += Monsters[i]
        Monsters[i] = 0
        k = Monsters[i + 1] + r
        if k >= 0:
            res -= r
            Monsters[i + 1] += r
        else:
            res += Monsters[i + 1]
            Monsters[i + 1] = 0
print(res)

import sys

input = sys.stdin.buffer.readline
import os
from math import *

n = int(eval(input()))
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ans = 0
for i in range(n):
    if arr[i] >= brr[i]:
        ans += brr[i]
    else:
        if arr[i] + arr[i + 1] >= brr[i]:
            ans += brr[i]
            arr[i + 1] = arr[i] + arr[i + 1] - brr[i]
        else:
            ans += arr[i] + arr[i + 1]
            arr[i + 1] = 0
print(ans)

-N = int(eval(input())) -Monsters = [int(i) for i in input().split()] -Heroes = [int(i) for i in input().split()] -res = 0 -for i in range(N): -    r = Monsters[i] - Heroes[i] -    if r >= 0: -        Monsters[i] -= Heroes[i] -        res += Heroes[i] +import sys + +input = sys.stdin.buffer.readline +import os +from math import * + +n = int(eval(input())) +arr = list(map(int, input().split())) +brr = list(map(int, input().split())) +ans = 0 +for i in range(n): +    if arr[i] >= brr[i]: +        ans += brr[i] -        res += Monsters[i] -        Monsters[i] = 0 -        k = Monsters[i + 1] + r -        if k >= 0: -            res -= r -            Monsters[i + 1] += r +        if arr[i] + arr[i + 1] >= brr[i]: +            ans += brr[i] +            arr[i + 1] = arr[i] + arr[i + 1] - brr[i] -            res += Monsters[i + 1] -            Monsters[i + 1] = 0 -print(res) +            ans += arr[i] + arr[i + 1] +            arr[i + 1] = 0 +print(ans)