import math

import re

import copy

import sys



n = int(eval(input()))

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

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

c = 0



for i in range(n):

    c += min(a[i],b[i])

    if a[i] < b[i]:

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

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



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

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

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

ans = 0

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

    ans += min(a[i]+a[i+1],b[i])

    a[i] = max(a[i]-max(b[i]-a[i+1],0),0)

print(ans)

import math
import re
import copy
import sys

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

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

-import math -import re -import copy -import sys - -c = 0 -for i in range(n): -    c += min(a[i], b[i]) -    if a[i] < b[i]: -        c += min(a[i + 1], b[i] - a[i]) -        a[i + 1] -= min(a[i + 1], b[i] - a[i]) -print(c) +ans = 0 +for i in range(n - 1, -1, -1): +    ans += min(a[i] + a[i + 1], b[i]) +    a[i] = max(a[i] - max(b[i] - a[i + 1], 0), 0) +print(ans)