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

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

eaten = 0

ans = 0

for i in range(N-1):

    if A[i]+A[i+1]<=x:continue

    else:

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

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

        ans += eaten

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

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

ans = 0

for i in range(1,N):

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

    if cnt > 0:

        A[i] = max(0,A[i]-cnt)

        ans += cnt

print(ans)
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
eaten = 0
ans = 0
for i in range(N - 1):
    if A[i] + A[i + 1] <= x:
        continue
    else:
        eaten = A[i] + A[i + 1] - x
        A[i + 1] = max(0, A[i + 1] - eaten)
        ans += eaten
print(ans)

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

-eaten = 0 -for i in range(N - 1): -    if A[i] + A[i + 1] <= x: -        continue -    else: -        eaten = A[i] + A[i + 1] - x -        A[i + 1] = max(0, A[i + 1] - eaten) -        ans += eaten +for i in range(1, N): +    cnt = A[i - 1] + A[i] - x +    if cnt > 0: +        A[i] = max(0, A[i] - cnt) +        ans += cnt