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(1,n):

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

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

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

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(1,n):

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

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

    a[i]-=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(1, n):
    if a[i - 1] + a[i] > x:
        ans += a[i - 1] + a[i] - x
        a[i] = x - a[i - 1]
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(1, n):
    if a[i] + a[i - 1] > x:
        ans += a[i] + a[i - 1] - x
        a[i] -= a[i] + a[i - 1] - x
print(ans)

-    ans = a[0] - x +    ans += a[0] - x -    if a[i - 1] + a[i] > x: -        ans += a[i - 1] + a[i] - x -        a[i] = x - a[i - 1] +    if a[i] + a[i - 1] > x: +        ans += a[i] + a[i - 1] - x +        a[i] -= a[i] + a[i - 1] - x