n = int(eval(input()))

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

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



if b_li[0]<b_li[-1]:

    a_li = a_li[::-1]

    b_li = b_li[::-1]



ans = 0

for i in range(0,n):

    attack = min(a_li[i],b_li[i])

    attack2 = min(a_li[i+1],b_li[i]-min(a_li[i],b_li[i]))

    a_li[i]-=attack

    a_li[i+1]-=attack2

    b_li[i]-=(attack+attack2)

    ans+=(attack+attack2)



print(ans)



n = int(eval(input()))

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

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



ans=0

for i in range(n):

    first_attack=0

    second_attack=0



    first_attack = min(b_input[i],a_input[i])

    a_input[i]-=first_attack

    if first_attack<b_input[i]:

        second_attack = min(a_input[i+1],b_input[i]-first_attack)

        a_input[i+1]-= second_attack

    ans+=first_attack+second_attack



print(ans)

n = int(eval(input()))
a_li = [int(i) for i in input().split()]
b_li = [int(i) for i in input().split()]
if b_li[0] < b_li[-1]:
    a_li = a_li[::-1]
    b_li = b_li[::-1]
ans = 0
for i in range(0, n):
    attack = min(a_li[i], b_li[i])
    attack2 = min(a_li[i + 1], b_li[i] - min(a_li[i], b_li[i]))
    a_li[i] -= attack
    a_li[i + 1] -= attack2
    b_li[i] -= attack + attack2
    ans += attack + attack2
print(ans)

n = int(eval(input()))
a_input = list(map(int, input().split()))
b_input = list(map(int, input().split()))
ans = 0
for i in range(n):
    first_attack = 0
    second_attack = 0
    first_attack = min(b_input[i], a_input[i])
    a_input[i] -= first_attack
    if first_attack < b_input[i]:
        second_attack = min(a_input[i + 1], b_input[i] - first_attack)
        a_input[i + 1] -= second_attack
    ans += first_attack + second_attack
print(ans)

-a_li = [int(i) for i in input().split()] -b_li = [int(i) for i in input().split()] -if b_li[0] < b_li[-1]: -    a_li = a_li[::-1] -    b_li = b_li[::-1] +a_input = list(map(int, input().split())) +b_input = list(map(int, input().split())) -for i in range(0, n): -    attack = min(a_li[i], b_li[i]) -    attack2 = min(a_li[i + 1], b_li[i] - min(a_li[i], b_li[i])) -    a_li[i] -= attack -    a_li[i + 1] -= attack2 -    b_li[i] -= attack + attack2 -    ans += attack + attack2 +for i in range(n): +    first_attack = 0 +    second_attack = 0 +    first_attack = min(b_input[i], a_input[i]) +    a_input[i] -= first_attack +    if first_attack < b_input[i]: +        second_attack = min(a_input[i + 1], b_input[i] - first_attack) +        a_input[i + 1] -= second_attack +    ans += first_attack + second_attack