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

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



sumA=[A[i]+A[i+1] for i in range(N-1)]



count=0

for i in range(N-1):

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

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

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

        if A[i+1]<0:

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

            A[i+1]=0

print(count)

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

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

count=0

for i in range(N-1):

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

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

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

        if A[i+1]<0:

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

            A[i+1]=0

print(count)

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

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

-sumA = [A[i] + A[i + 1] for i in range(N - 1)]