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

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



ans = 0



if a[0] > x:

    ans += (a[0]-x)

    a[0] = x

for i in range(len(a)-1):

    if sum(a[i:i+2]) > x:

        ans += (sum(a[i:i+2]) - x)

        a[i+1] -= (sum(a[i:i+2]) - x)



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

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

 

ans = 0

 

if a[0] > x:

    ans += (a[0]-x)

    a[0] = x

for i in range(len(a)-1):

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

        ans += (a[i]+a[i+1]-x)

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

 

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

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

-    if sum(a[i : i + 2]) > x: -        ans += sum(a[i : i + 2]) - x -        a[i + 1] -= sum(a[i : i + 2]) - x +    if a[i] + a[i + 1] > x: +        ans += a[i] + a[i + 1] - x +        a[i + 1] -= a[i] + a[i + 1] - x