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

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

ans = 0

for i in range(1, n):

    if A[i-1]+A[i] <= x:

        continue

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

    ans += eat

    A[i] = max(0, A[i]-eat)



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

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

ans = 0

for i in range(n):

    if i == 0:

        if A[i] <= x:

            continue

        eat = A[i] - x

        ans += eat

        A[i] = A[i] - eat

        continue

    if A[i-1]+A[i] <= x:

        continue

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

    ans += eat

    A[i] = A[i] - eat



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

n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i == 0:
        if A[i] <= x:
            continue
        eat = A[i] - x
        ans += eat
        A[i] = A[i] - eat
        continue
    if A[i - 1] + A[i] <= x:
        continue
    eat = A[i - 1] + A[i] - x
    ans += eat
    A[i] = A[i] - eat
print(ans)

-for i in range(1, n): +for i in range(n): +    if i == 0: +        if A[i] <= x: +            continue +        eat = A[i] - x +        ans += eat +        A[i] = A[i] - eat +        continue -    A[i] = max(0, A[i] - eat) +    A[i] = A[i] - eat