n=int(eval(input()))

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

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

sum=0

for i in range(n-1):

    if B[i]-A[i]>0:

        if A[i+1]-(B[i]-A[i])<0:

            

       #     print(A[i]+A[i+1])

            sum+=A[i]+A[i+1]

            A[i+1]=0

        else:

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

      #      print(B[i])

            sum+=B[i]

    else:

     #   print(B[i])

        sum+=B[i]



if B[n-1]<A[n-1]+A[n]:

    #print(B[n-1])

    sum+=B[n-1]

else:

    #print(A[n-1]+A[n])

    sum+=A[n-1]+A[n]

print(sum)

n=int(eval(input()))

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

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

sum=0

for i in range(n-1):

    x=B[i]-A[i]

    if x>0:

        if A[i+1]-(x)<0:

            

       #     print(A[i]+A[i+1])

            sum+=A[i]+A[i+1]

            A[i+1]=0

        else:

            A[i+1]+=-(x)

      #      print(B[i])

            sum+=B[i]

    else:

     #   print(B[i])

        sum+=B[i]



if B[n-1]<A[n-1]+A[n]:

    #print(B[n-1])

    sum+=B[n-1]

else:

    #print(A[n-1]+A[n])

    sum+=A[n-1]+A[n]

print(sum)

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

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

-    if B[i] - A[i] > 0: -        if A[i + 1] - (B[i] - A[i]) < 0: +    x = B[i] - A[i] +    if x > 0: +        if A[i + 1] - (x) < 0: -            A[i + 1] += -(B[i] - A[i]) +            A[i + 1] += -(x)