import math



n = int(eval(input()))

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

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



ans = 0



for i in reversed(list(range(n))):

	if a[i+1] - b[i] <= 0:

		ans += a[i+1]

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

		a[i+1] = 0

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

			ans += a[i]

			b[i] -= a[i]

			a[i] = 0

		else:

			ans += b[i]

			a[i] -= b[i]

			b[i] = 0

	else:

		ans += b[i]

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

		b[i] = 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:

		ans += a[i]

		if a[i+1] < b[i] - a[i]:

			ans += a[i+1]

			a[i+1] = 0

		else:

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

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



print(ans)

import math

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

-import math - -for i in reversed(list(range(n))): -    if a[i + 1] - b[i] <= 0: -        ans += a[i + 1] -        b[i] -= a[i + 1] -        a[i + 1] = 0 -        if a[i] - b[i] <= 0: -            ans += a[i] -            b[i] -= a[i] -            a[i] = 0 +for i in range(n): +    if a[i] >= b[i]: +        ans += b[i] +    else: +        ans += a[i] +        if a[i + 1] < b[i] - a[i]: +            ans += a[i + 1] +            a[i + 1] = 0 -            ans += b[i] -            a[i] -= b[i] -            b[i] = 0 -    else: -        ans += b[i] -        a[i + 1] -= b[i] -        b[i] = 0 +            ans += b[i] - a[i] +            a[i + 1] -= b[i] - a[i]