# 頭から倒せるだけ倒していく



n = int(eval(input()))

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

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



count = 0

for i in range(n):

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

    count += a[i]

    b[i] -= a[i]

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

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

  else:

    count += b[i]



print(count)
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 += a[i]

        b[i] -= a[i]

        a[i] = 0

    else:

        ans += b[i]

        a[i] -= b[i]

        b[i] = 0

    if b[i] > 0:

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

        if tmp == 0:

            ans += a[i + 1]

        else:

            ans += b[i]

        a[i + 1] = tmp

print(ans)
# 頭から倒せるだけ倒していく
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in range(n):
    if a[i] <= b[i]:
        count += a[i]
        b[i] -= a[i]
        count += min(a[i + 1], b[i])
        a[i + 1] = max(0, a[i + 1] - b[i])
    else:
        count += b[i]
print(count)

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 += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        ans += b[i]
        a[i] -= b[i]
        b[i] = 0
    if b[i] > 0:
        tmp = max(0, a[i + 1] - b[i])
        if tmp == 0:
            ans += a[i + 1]
        else:
            ans += b[i]
        a[i + 1] = tmp
print(ans)

-# 頭から倒せるだけ倒していく -count = 0 +ans = 0 -        count += a[i] +        ans += a[i] -        count += min(a[i + 1], b[i]) -        a[i + 1] = max(0, a[i + 1] - b[i]) +        a[i] = 0 -        count += b[i] -print(count) +        ans += b[i] +        a[i] -= b[i] +        b[i] = 0 +    if b[i] > 0: +        tmp = max(0, a[i + 1] - b[i]) +        if tmp == 0: +            ans += a[i + 1] +        else: +            ans += b[i] +        a[i + 1] = tmp +print(ans)