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

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

count= 0

for i in range(n-1):

    count += max(0,a[i]+a[i+1]-x)

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

        if (a[i]+a[i+1]-x) > a[i+1]:

            a[i+1] = 0

        else:

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

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

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

ans,count=0,0

for i in range(n-1):

    count = max(0,a[i]+a[i+1]-x)

    a[i+1] -= min(a[i+1],count)

    ans += count

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

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans, count = 0, 0
for i in range(n - 1):
    count = max(0, a[i] + a[i + 1] - x)
    a[i + 1] -= min(a[i + 1], count)
    ans += count
print(ans)

-count = 0 +ans, count = 0, 0 -    count += max(0, a[i] + a[i + 1] - x) -    if a[i] + a[i + 1] > x: -        if (a[i] + a[i + 1] - x) > a[i + 1]: -            a[i + 1] = 0 -        else: -            a[i + 1] -= a[i] + a[i + 1] - x -print(count) +    count = max(0, a[i] + a[i + 1] - x) +    a[i + 1] -= min(a[i + 1], count) +    ans += count +print(ans)