n = int(eval(input()))

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

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



ans = 0

t = 0

for i in range(n):

  t = a[i]

  if t >= b[i]:

    t -= b[i]

    ans += b[i]

  else:

    ans += t

    b[i] -= t

    t = 0

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

      ans += b[i]

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

    else:

      ans += a[i+1]

      a[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 range(n):

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

    ans += b[i]

  else:

    ans += a[i]

    b[i] -= a[i]

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

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

      ans += b[i]

    else:

      ans += a[i+1]

      a[i+1] = 0

      

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

-t = 0 -    t = a[i] -    if t >= b[i]: -        t -= b[i] +    if a[i] >= b[i]: -        ans += t -        b[i] -= t -        t = 0 +        ans += a[i] +        b[i] -= a[i] +            a[i + 1] -= b[i] -            a[i + 1] -= b[i]