n = int(eval(input()))

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

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



ans = 0

for i in range(n):

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

        if a[i]+a[i+1] > b[i]:

            all_enemy = a[i] + a[i + 1]

            ans += b[i]

            a[i+1] = a[i]+a[i+1] - b[i]

        else:

            all_enemy = a[i] + a[i + 1]

            ans += all_enemy

            a[i+1] = 0

    else:

        ans += b[i]



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

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

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



ans = 0

for i in range(n):

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

        all_enemy = a[i] + a[i + 1]

        if all_enemy > b[i]:

            ans += b[i]

            a[i+1] = all_enemy - b[i]

        else:

            ans += all_enemy

            a[i+1] = 0

    else:

        ans += b[i]



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

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

-        if a[i] + a[i + 1] > b[i]: -            all_enemy = a[i] + a[i + 1] +        all_enemy = a[i] + a[i + 1] +        if all_enemy > b[i]: -            a[i + 1] = a[i] + a[i + 1] - b[i] +            a[i + 1] = all_enemy - b[i] -            all_enemy = a[i] + a[i + 1]