N,X,*A = list(map(int,open(0).read().split()))

A+=[0]

s = 0



for n in range(N):

  d=max(0,A[n]+A[n-1]-X)

  s+=d

  A[n]-=d



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

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

pre = 0

ans = 0



for a in A:

  eat = max(0,pre+a-x)

  pre = a - eat

  ans+= eat



print(ans)
N, X, *A = list(map(int, open(0).read().split()))
A += [0]
s = 0
for n in range(N):
    d = max(0, A[n] + A[n - 1] - X)
    s += d
    A[n] -= d
print(s)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
pre = 0
ans = 0
for a in A:
    eat = max(0, pre + a - x)
    pre = a - eat
    ans += eat
print(ans)

-N, X, *A = list(map(int, open(0).read().split())) -A += [0] -s = 0 -for n in range(N): -    d = max(0, A[n] + A[n - 1] - X) -    s += d -    A[n] -= d -print(s) +N, x = list(map(int, input().split())) +A = list(map(int, input().split())) +pre = 0 +ans = 0 +for a in A: +    eat = max(0, pre + a - x) +    pre = a - eat +    ans += eat +print(ans)