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+1))):

  if i == n:

    temp = min(a[i], b[i-1])

    ans += temp

    b[i-1] -= temp

  elif i == 0:

    ans += min(a[i], b[i])

  else:

    temp1 = min(a[i], b[i])

    ans += temp1

    a[i] -= temp1

    temp2 = min(a[i], b[i-1])

    ans += temp2

    b[i-1] -= temp2

print(ans)

    
n = int(eval(input()))

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

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



ans = 0

for i in reversed(list(range(1, n+1))):

    if A[i] <= B[i-1]:

        ans += A[i]

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

        if A[i-1] >= B[i-1]:

            ans += B[i-1]

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

        else:

            ans += A[i-1]

            A[i-1] = 0

    else:

        ans += B[i-1]

        B[i-1] = 0

print(ans)
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 + 1))):
    if i == n:
        temp = min(a[i], b[i - 1])
        ans += temp
        b[i - 1] -= temp
    elif i == 0:
        ans += min(a[i], b[i])
    else:
        temp1 = min(a[i], b[i])
        ans += temp1
        a[i] -= temp1
        temp2 = min(a[i], b[i - 1])
        ans += temp2
        b[i - 1] -= temp2
print(ans)

n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in reversed(list(range(1, n + 1))):
    if A[i] <= B[i - 1]:
        ans += A[i]
        B[i - 1] -= A[i]
        if A[i - 1] >= B[i - 1]:
            ans += B[i - 1]
            A[i - 1] -= B[i - 1]
        else:
            ans += A[i - 1]
            A[i - 1] = 0
    else:
        ans += B[i - 1]
        B[i - 1] = 0
print(ans)

-a = list(map(int, input().split())) -b = list(map(int, input().split())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) -for i in reversed(list(range(n + 1))): -    if i == n: -        temp = min(a[i], b[i - 1]) -        ans += temp -        b[i - 1] -= temp -    elif i == 0: -        ans += min(a[i], b[i]) +for i in reversed(list(range(1, n + 1))): +    if A[i] <= B[i - 1]: +        ans += A[i] +        B[i - 1] -= A[i] +        if A[i - 1] >= B[i - 1]: +            ans += B[i - 1] +            A[i - 1] -= B[i - 1] +        else: +            ans += A[i - 1] +            A[i - 1] = 0 -        temp1 = min(a[i], b[i]) -        ans += temp1 -        a[i] -= temp1 -        temp2 = min(a[i], b[i - 1]) -        ans += temp2 -        b[i - 1] -= temp2 +        ans += B[i - 1] +        B[i - 1] = 0