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

A = [0] + list(map(int, input().split()))

ans = 0

for i in range(N):

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

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

        ans += tmp

        A[i + 1] -= tmp

print(ans)

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

ans = 0

for i in range(1, N):

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

    if required <= 0:

        continue

    elif required <= A[i]:

        A[i] -= required

    else:

        A[i] = 0

        rem = required - A[i]

        A[i - 1] -= rem

    ans += required



print(ans)

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

N, x, *A = list(map(int, open(0).read().split()))
ans = 0
for i in range(1, N):
    required = (A[i] + A[i - 1]) - x
    if required <= 0:
        continue
    elif required <= A[i]:
        A[i] -= required
    else:
        A[i] = 0
        rem = required - A[i]
        A[i - 1] -= rem
    ans += required
print(ans)

-N, x = list(map(int, input().split())) -A = [0] + list(map(int, input().split())) +N, x, *A = list(map(int, open(0).read().split())) -for i in range(N): -    if A[i] + A[i + 1] > x: -        tmp = A[i] + A[i + 1] - x -        ans += tmp -        A[i + 1] -= tmp +for i in range(1, N): +    required = (A[i] + A[i - 1]) - x +    if required <= 0: +        continue +    elif required <= A[i]: +        A[i] -= required +    else: +        A[i] = 0 +        rem = required - A[i] +        A[i - 1] -= rem +    ans += required