n=int(eval(input()))

monsters=[int(x) for x in input().split(' ')]

powers=[int(x) for x in input().split(' ')]

ans=0

for i in range(n):

	t=min(monsters[i],powers[i])

	ans+=t

	t2=min(monsters[i+1],powers[i]-t)

	ans+=t2

	monsters[i+1]-=t2

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

A=[int(x) for x in input().split(' ')]

B=[int(x) for x in input().split(' ')]

ans=0

for i in range(n):

	if (A[i]>=B[i]):

		ans+=B[i]

	else:

		ans+=A[i]

		B[i]-=A[i]



		if (A[i+1]>=B[i]):

			ans+=B[i]

			A[i+1]-=B[i]

		else:

			ans+=A[i+1]

			A[i+1]=0

print(ans)
n = int(eval(input()))
monsters = [int(x) for x in input().split(" ")]
powers = [int(x) for x in input().split(" ")]
ans = 0
for i in range(n):
    t = min(monsters[i], powers[i])
    ans += t
    t2 = min(monsters[i + 1], powers[i] - t)
    ans += t2
    monsters[i + 1] -= t2
print(ans)

n = int(eval(input()))
A = [int(x) for x in input().split(" ")]
B = [int(x) for x in input().split(" ")]
ans = 0
for i in range(n):
    if A[i] >= B[i]:
        ans += B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        if A[i + 1] >= B[i]:
            ans += B[i]
            A[i + 1] -= B[i]
        else:
            ans += A[i + 1]
            A[i + 1] = 0
print(ans)

-monsters = [int(x) for x in input().split(" ")] -powers = [int(x) for x in input().split(" ")] +A = [int(x) for x in input().split(" ")] +B = [int(x) for x in input().split(" ")] -    t = min(monsters[i], powers[i]) -    ans += t -    t2 = min(monsters[i + 1], powers[i] - t) -    ans += t2 -    monsters[i + 1] -= t2 +    if A[i] >= B[i]: +        ans += B[i] +    else: +        ans += A[i] +        B[i] -= A[i] +        if A[i + 1] >= B[i]: +            ans += B[i] +            A[i + 1] -= B[i] +        else: +            ans += A[i + 1] +            A[i + 1] = 0