n=int(eval(input()))

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

b=list(map(int,input().split()))+[0]

ans=0

for i in range(n+1):

  if a[i]>=b[i]:

    ans+=b[i]

  else:

    ans+=a[i]

    d=b[i]-a[i]

    if a[i+1]>d:

      ans+=d

      a[i+1]-=d

    else:

      ans+=a[i+1]

      a[i+1]=0

print(ans)
n=int(eval(input()))

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

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

ans=0

for i in range(n):

  if a[i]>=b[i]:

    ans+=b[i]

  else:

    res=b[i]-a[i]

    if a[i+1]-res<0:

      ans+=a[i]+a[i+1]

      a[i+1]=0

    else:

      ans+=b[i]

      a[i+1]-=res

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

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

-b = list(map(int, input().split())) + [0] +b = list(map(int, input().split())) -for i in range(n + 1): +for i in range(n): -        ans += a[i] -        d = b[i] - a[i] -        if a[i + 1] > d: -            ans += d -            a[i + 1] -= d +        res = b[i] - a[i] +        if a[i + 1] - res < 0: +            ans += a[i] + a[i + 1] +            a[i + 1] = 0 -            ans += a[i + 1] -            a[i + 1] = 0 +            ans += b[i] +            a[i + 1] -= res