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

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

ans=0

pre=0

for i in range(N-1):

    s=A[i]+A[i+1]-pre

    ans+=max(0,s-x)

    pre=min(max(0,s-x),A[i+1])

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

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

ans = 0

for i in range(N - 1):

    w = A[i] + A[i + 1]

    if w <= x: continue

    r = max(0, A[i + 1] - (w - x))

    l = x - r

    ans += A[i] - l + A[i + 1] - r

    A[i + 1] = r

print(ans)

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

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

-A = list(map(int, input().split())) +(*A,) = list(map(int, input().split())) -pre = 0 -    s = A[i] + A[i + 1] - pre -    ans += max(0, s - x) -    pre = min(max(0, s - x), A[i + 1]) +    w = A[i] + A[i + 1] +    if w <= x: +        continue +    r = max(0, A[i + 1] - (w - x)) +    l = x - r +    ans += A[i] - l + A[i + 1] - r +    A[i + 1] = r