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

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



ans=0



if A[0]>X:

    ans+=A[0]-X

    A[0]=X 



i=0

while i+1<=N-1:

    if A[i]+A[i+1]>X:

        ans+=A[i]+A[i+1]-X

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

    i+=1



print(ans)
N,X=list(map(int,input().split()))

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



ans=0

if A[0]>X:

    ans+=A[0]-X

    A[0]=X



i=1

while i<N:

    if A[i]+A[i-1]>X:

        ans+=A[i]+A[i-1]-X

        A[i]=X-A[i-1]

    i+=1

        

print(ans)
N, X = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
ans = 0
if A[0] > X:
    ans += A[0] - X
    A[0] = X
i = 0
while i + 1 <= N - 1:
    if A[i] + A[i + 1] > X:
        ans += A[i] + A[i + 1] - X
        A[i + 1] = X - A[i]
    i += 1
print(ans)

N, X = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
ans = 0
if A[0] > X:
    ans += A[0] - X
    A[0] = X
i = 1
while i < N:
    if A[i] + A[i - 1] > X:
        ans += A[i] + A[i - 1] - X
        A[i] = X - A[i - 1]
    i += 1
print(ans)

-i = 0 -while i + 1 <= N - 1: -    if A[i] + A[i + 1] > X: -        ans += A[i] + A[i + 1] - X -        A[i + 1] = X - A[i] +i = 1 +while i < N: +    if A[i] + A[i - 1] > X: +        ans += A[i] + A[i - 1] - X +        A[i] = X - A[i - 1]