N = int(eval(input()))

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

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

s = 0

for i in range(N):

  l = min(m[i],b[i])

  s += l

  m[i] -= l

  b[i] -= l

  

  r = min(m[i+1],b[i])

  s += r

  m[i+1] -= r

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

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

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

c = 0

for i in range(n):

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

    c+=int(b[i])

  else:

    if (a[i]+a[i+1])>=b[i]:

      c+=int(b[i])

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

    else:

      c+=int(a[i]+a[i+1])

      a[i+1]=0

print(c)
N = int(eval(input()))
m = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(N):
    l = min(m[i], b[i])
    s += l
    m[i] -= l
    b[i] -= l
    r = min(m[i + 1], b[i])
    s += r
    m[i + 1] -= r
print(s)

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(n):
    if a[i] >= b[i]:
        c += int(b[i])
    else:
        if (a[i] + a[i + 1]) >= b[i]:
            c += int(b[i])
            a[i + 1] = a[i] + a[i + 1] - b[i]
        else:
            c += int(a[i] + a[i + 1])
            a[i + 1] = 0
print(c)

-N = int(eval(input())) -m = list(map(int, input().split())) +n = int(eval(input())) +a = list(map(int, input().split())) -s = 0 -for i in range(N): -    l = min(m[i], b[i]) -    s += l -    m[i] -= l -    b[i] -= l -    r = min(m[i + 1], b[i]) -    s += r -    m[i + 1] -= r -print(s) +c = 0 +for i in range(n): +    if a[i] >= b[i]: +        c += int(b[i]) +    else: +        if (a[i] + a[i + 1]) >= b[i]: +            c += int(b[i]) +            a[i + 1] = a[i] + a[i + 1] - b[i] +        else: +            c += int(a[i] + a[i + 1]) +            a[i + 1] = 0 +print(c)