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:

        b = a[i] + a[i-1] - x

        minab = min(a[i], b)

        a[i] -= minab

        cnt += minab

        

        b -= minab

        cnt += b

        a[i-1] -= b

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] - (x - a[i-1])

        a[i] = x - a[i-1]

print(cnt)
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:
        b = a[i] + a[i - 1] - x
        minab = min(a[i], b)
        a[i] -= minab
        cnt += minab
        b -= minab
        cnt += b
        a[i - 1] -= b
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] - (x - a[i - 1])
        a[i] = x - a[i - 1]
print(cnt)

+if a[0] > x: +    cnt += a[0] - x +    a[0] = x -        b = a[i] + a[i - 1] - x -        minab = min(a[i], b) -        a[i] -= minab -        cnt += minab -        b -= minab -        cnt += b -        a[i - 1] -= b +        cnt += a[i] - (x - a[i - 1]) +        a[i] = x - a[i - 1]