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

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

ans = 0

for i in range(1,N):

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

    if A[i]>=y:

        A[i] -= y

    else:

        A[i] = 0

    ans += y

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

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

cnt = 0

for i in range(1,N):

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

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

        if A[i]>=d:

            A[i] -= d

            cnt += d

        else:

            A[i]=0

            cnt += A[i]

            d -= A[i]

            A[i-1] -= d

            cnt += d

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

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

-ans = 0 +cnt = 0 -    y = max(A[i] + A[i - 1] - x, 0) -    if A[i] >= y: -        A[i] -= y -    else: -        A[i] = 0 -    ans += y -print(ans) +    if A[i] + A[i - 1] > x: +        d = A[i] + A[i - 1] - x +        if A[i] >= d: +            A[i] -= d +            cnt += d +        else: +            A[i] = 0 +            cnt += A[i] +            d -= A[i] +            A[i - 1] -= d +            cnt += d +print(cnt)