N, x = list(map(int, input().split()))

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



# if len(A) % 2 == 0:

#     A = A + [0]

# print('A', A)



ans = 0

for i in range(1, N):

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

    diff = total - x

    if diff <= 0:

        continue

    v1 = min(A[i], diff)

    v2 = diff - v1

    A[i] -= v1

    A[i - 1] -= v2

    ans += v1 + v2

    # print('A', A)

print(ans)

N, x = list(map(int, input().split()))

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

sum_A = sum(A)



for i in range(1, N):

    diff = A[i - 1] + A[i] - x

    if diff <= 0:

        continue

    v1 = min(A[i], diff)

    v2 = diff - v1

    A[i] -= v1

    A[i - 1] -= v2

    # print('A', A)

ans = sum_A - sum(A)

print(ans)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
# if len(A) % 2 == 0:
#     A = A + [0]
# print('A', A)
ans = 0
for i in range(1, N):
    total = A[i - 1] + A[i]
    diff = total - x
    if diff <= 0:
        continue
    v1 = min(A[i], diff)
    v2 = diff - v1
    A[i] -= v1
    A[i - 1] -= v2
    ans += v1 + v2
    # print('A', A)
print(ans)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
sum_A = sum(A)
for i in range(1, N):
    diff = A[i - 1] + A[i] - x
    if diff <= 0:
        continue
    v1 = min(A[i], diff)
    v2 = diff - v1
    A[i] -= v1
    A[i - 1] -= v2
    # print('A', A)
ans = sum_A - sum(A)
print(ans)

-# if len(A) % 2 == 0: -#     A = A + [0] -# print('A', A) -ans = 0 +sum_A = sum(A) -    total = A[i - 1] + A[i] -    diff = total - x +    diff = A[i - 1] + A[i] - x -    ans += v1 + v2 +ans = sum_A - sum(A)