n,x,*a=list(map(int,open(0).read().split()));r=0

for i in range(1,n):e=max(a[i]+a[i-1]-x,0);a[i]-=min(e,a[i]);r+=e

print(r)
n,x,*a=list(map(int,open(0).read().split()));t=r=0

for i in a:t=min(i,x-t);r+=i-t

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

n, x, *a = list(map(int, open(0).read().split()))
t = r = 0
for i in a:
    t = min(i, x - t)
    r += i - t
print(r)

-r = 0 -for i in range(1, n): -    e = max(a[i] + a[i - 1] - x, 0) -    a[i] -= min(e, a[i]) -    r += e +t = r = 0 +for i in a: +    t = min(i, x - t) +    r += i - t