n = int(eval(input()))

a = [int(e) for e in input().split()]

b = [int(e) for e in input().split()]

result = 0

for i in range(n):

  if a[i] > b[i]:

    result += b[i]

    a[i] -= b[i]

    b[i] = 0

  else:

    result += a[i]

    b[i] -= a[i]

    a[i] = 0

    if a[i + 1] > b[i]:

      result += b[i]

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

      b[i] = 0

    else:

      result += a[i + 1]

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

      a[i + 1] = 0

print(result)
N = int(eval(input()))

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

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



result = 0



for i in range(N):

    

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

        result += A[i]

        B[i] -= A[i]

        A[i] = 0

        

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

            result += A[i+1]

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

            A[i+1] = 0

        else:

            result += B[i]

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

            B[i] = 0

        

    else:

        result += B[i]

        A[i] -= B[i]

        B[i] = 0



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

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

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