N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A=[min(x,a)for a in A]

for i in range(N-1):A[i+1]-=max(0,A[i]+A[i+1]-x)

print((s-sum(A)))
N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A+=0,

for i in range(N):A[i]-=max(0,A[i]+A[i-1]-x)

print((s-sum(A)))
N, x, *A = list(map(int, open(0).read().split()))
s = sum(A)
A = [min(x, a) for a in A]
for i in range(N - 1):
    A[i + 1] -= max(0, A[i] + A[i + 1] - x)
print((s - sum(A)))

N, x, *A = list(map(int, open(0).read().split()))
s = sum(A)
A += (0,)
for i in range(N):
    A[i] -= max(0, A[i] + A[i - 1] - x)
print((s - sum(A)))

-A = [min(x, a) for a in A] -for i in range(N - 1): -    A[i + 1] -= max(0, A[i] + A[i + 1] - x) +A += (0,) +for i in range(N): +    A[i] -= max(0, A[i] + A[i - 1] - x)