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

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

cnt = 0

for i in range(1,N):

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

    if diff>0:

        cnt += diff

        A[i] -= min(A[i],diff)



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

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

cnt = 0

if A[0] > x:

    cnt += (A[0]-x)

    A[0] = x

for i in range(1,N):

    if A[i]+A[i-1] > x:

        cnt += (A[i]+A[i-1]-x)

        A[i] -= (A[i]+A[i-1]-x)

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

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

+if A[0] > x: +    cnt += A[0] - x +    A[0] = x -    diff = A[i] + A[i - 1] - x -    if diff > 0: -        cnt += diff -        A[i] -= min(A[i], diff) +    if A[i] + A[i - 1] > x: +        cnt += A[i] + A[i - 1] - x +        A[i] -= A[i] + A[i - 1] - x