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

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



cnt=0

pre=0



for i in range(N):

  dif=max(A[i]+pre-x,0)

  cnt+=dif

  A[i]-=dif

  pre=A[i]

  

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

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

if A[0]>x:

  cnt=A[0]-x

  A[0]=A[0]-cnt

else:

  cnt=0

for i in range(1,N):

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

  if gap>0:    

    cnt+=gap

    A[i]-=gap

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

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

-cnt = 0 -pre = 0 -for i in range(N): -    dif = max(A[i] + pre - x, 0) -    cnt += dif -    A[i] -= dif -    pre = A[i] +if A[0] > x: +    cnt = A[0] - x +    A[0] = A[0] - cnt +else: +    cnt = 0 +for i in range(1, N): +    gap = A[i] + A[i - 1] - x +    if gap > 0: +        cnt += gap +        A[i] -= gap