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

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



cnt = 0

for i in range(N - 1):

    sm = A[i] + A[i+1]

    if sm > x:

        diff = sm - x

        if A[i+1] >= diff:

            A[i+1] -= diff

        else:

            diff2 = diff - A[i+1]

            A[i+1] = 0

            A[i] -= diff2

        cnt += diff



print(cnt)

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

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





cnt = 0

if A[0] > x:

    cnt += A[0] - x

    A[0] = x



for i in range(N - 1):

    sm = A[i] + A[i+1]

    if sm > x:

        diff = sm - x

        A[i+1] -= diff

        cnt += diff



print(cnt)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    sm = A[i] + A[i + 1]
    if sm > x:
        diff = sm - x
        if A[i + 1] >= diff:
            A[i + 1] -= diff
        else:
            diff2 = diff - A[i + 1]
            A[i + 1] = 0
            A[i] -= diff2
        cnt += diff
print(cnt)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
if A[0] > x:
    cnt += A[0] - x
    A[0] = x
for i in range(N - 1):
    sm = A[i] + A[i + 1]
    if sm > x:
        diff = sm - x
        A[i + 1] -= diff
        cnt += diff
print(cnt)

+if A[0] > x: +    cnt += A[0] - x +    A[0] = x -        if A[i + 1] >= diff: -            A[i + 1] -= diff -        else: -            diff2 = diff - A[i + 1] -            A[i + 1] = 0 -            A[i] -= diff2 +        A[i + 1] -= diff