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

lst = [int(i) for i in input().split()]



cnt = 0



if lst[0] > x:

    cnt += lst[0]-x

    lst[0] = x



for i in range(n-1):

    dis = 0

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

        dis = lst[i] + lst[i+1] - x

        lst[i+1] -= dis

        cnt += dis



print(cnt)
n,k = list(map(int,input().split()))

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

ans = 0

if A[0]>k:

    ans += A[0]-k

    A[0] = k

for i in range(1, n):

    if A[i]+A[i-1]<=k:

        continue

    ans += (A[i]+A[i-1])-k

    A[i] = k-A[i-1]

print(ans)
n, x = list(map(int, input().split()))
lst = [int(i) for i in input().split()]
cnt = 0
if lst[0] > x:
    cnt += lst[0] - x
    lst[0] = x
for i in range(n - 1):
    dis = 0
    if lst[i] + lst[i + 1] > x:
        dis = lst[i] + lst[i + 1] - x
        lst[i + 1] -= dis
        cnt += dis
print(cnt)

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
if A[0] > k:
    ans += A[0] - k
    A[0] = k
for i in range(1, n):
    if A[i] + A[i - 1] <= k:
        continue
    ans += (A[i] + A[i - 1]) - k
    A[i] = k - A[i - 1]
print(ans)

-n, x = list(map(int, input().split())) -lst = [int(i) for i in input().split()] -cnt = 0 -if lst[0] > x: -    cnt += lst[0] - x -    lst[0] = x -for i in range(n - 1): -    dis = 0 -    if lst[i] + lst[i + 1] > x: -        dis = lst[i] + lst[i + 1] - x -        lst[i + 1] -= dis -        cnt += dis -print(cnt) +n, k = list(map(int, input().split())) +A = list(map(int, input().split())) +ans = 0 +if A[0] > k: +    ans += A[0] - k +    A[0] = k +for i in range(1, n): +    if A[i] + A[i - 1] <= k: +        continue +    ans += (A[i] + A[i - 1]) - k +    A[i] = k - A[i - 1] +print(ans)