def solve(string):

    n, *ab = list(map(int, string.split()))

    a, b = ab[:n + 1], ab[n + 1:]

    _sum = sum(a)

    for i, _b in enumerate(b[::-1]):

        diff = min(a[n - i], _b)

        _b -= diff

        a[n - i] -= diff

        a[n - i - 1] = max(0, a[n - i - 1] - _b)

    return str(_sum - sum(a))





if __name__ == '__main__':

    n = int(eval(input()))

    print((solve('{}\n'.format(n) + '\n'.join([eval(input()) for _ in range(2)]))))

N = int(eval(input()))

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

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

pow = 0

ans = 0

for a, b in zip(A, B):

    ans += a if pow >= a else pow

    a = 0 if pow >= a else a - pow

    ans += a if a <= b else b

    pow = b - a if b >= a else 0

ans += A[N] if pow >= A[N] else pow

print(ans)

def solve(string):
    n, *ab = list(map(int, string.split()))
    a, b = ab[: n + 1], ab[n + 1 :]
    _sum = sum(a)
    for i, _b in enumerate(b[::-1]):
        diff = min(a[n - i], _b)
        _b -= diff
        a[n - i] -= diff
        a[n - i - 1] = max(0, a[n - i - 1] - _b)
    return str(_sum - sum(a))


if __name__ == "__main__":
    n = int(eval(input()))
    print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(2)]))))

N = int(eval(input()))
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
pow = 0
ans = 0
for a, b in zip(A, B):
    ans += a if pow >= a else pow
    a = 0 if pow >= a else a - pow
    ans += a if a <= b else b
    pow = b - a if b >= a else 0
ans += A[N] if pow >= A[N] else pow
print(ans)

-def solve(string): -    n, *ab = list(map(int, string.split())) -    a, b = ab[: n + 1], ab[n + 1 :] -    _sum = sum(a) -    for i, _b in enumerate(b[::-1]): -        diff = min(a[n - i], _b) -        _b -= diff -        a[n - i] -= diff -        a[n - i - 1] = max(0, a[n - i - 1] - _b) -    return str(_sum - sum(a)) - - -if __name__ == "__main__": -    n = int(eval(input())) -    print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(2)])))) +N = int(eval(input())) +A = [int(a) for a in input().split()] +B = [int(b) for b in input().split()] +pow = 0 +ans = 0 +for a, b in zip(A, B): +    ans += a if pow >= a else pow +    a = 0 if pow >= a else a - pow +    ans += a if a <= b else b +    pow = b - a if b >= a else 0 +ans += A[N] if pow >= A[N] else pow +print(ans)