N,X=(int(T) for T in input().split())

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

ans=0

for i in range(0,N-1):

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

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

        ans=s+ans

        A[i]=A[i]-max(0,A[i]-A[i+1])

        A[i+1]=max(0,A[i+1]-s)

print(ans)

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

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

ans=0

for i in range(1,N):

    tmp=a[i-1]+a[i]

    if tmp>x:

        ans+=tmp-x

        if a[i]>=tmp-x:

            a[i]-=tmp-x

        else:

            a[i]=0

print(ans)

N, X = (int(T) for T in input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(0, N - 1):
    if A[i] + A[i + 1] > X:
        s = A[i] + A[i + 1] - X
        ans = s + ans
        A[i] = A[i] - max(0, A[i] - A[i + 1])
        A[i + 1] = max(0, A[i + 1] - s)
print(ans)

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    tmp = a[i - 1] + a[i]
    if tmp > x:
        ans += tmp - x
        if a[i] >= tmp - x:
            a[i] -= tmp - x
        else:
            a[i] = 0
print(ans)

-N, X = (int(T) for T in input().split()) -A = list(map(int, input().split())) +N, x = list(map(int, input().split())) +a = list(map(int, input().split())) -for i in range(0, N - 1): -    if A[i] + A[i + 1] > X: -        s = A[i] + A[i + 1] - X -        ans = s + ans -        A[i] = A[i] - max(0, A[i] - A[i + 1]) -        A[i + 1] = max(0, A[i + 1] - s) +for i in range(1, N): +    tmp = a[i - 1] + a[i] +    if tmp > x: +        ans += tmp - x +        if a[i] >= tmp - x: +            a[i] -= tmp - x +        else: +            a[i] = 0