Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. 

Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times. 

Polycarp analysed all his affairs over the next n days and made a sequence of n integers a_1, a_2, ..., a_{n}, where a_{i} is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).

Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times. 

Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b_1, b_2, ..., b_{n} (b_{i} ≥ a_{i}), where b_{i} means the total number of walks with the dog on the i-th day.


-----Input-----

The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days. 

The second line contains integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned. 


-----Output-----

In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days. 

In the second line print n integers b_1, b_2, ..., b_{n}, where b_{i} — the total number of walks on the i-th day according to the found solutions (a_{i} ≤ b_{i} for all i from 1 to n). If there are multiple solutions, print any of them. 


-----Examples-----
Input
3 5
2 0 1

Output
4
2 3 2

Input
3 1
0 0 0

Output
1
0 1 0

Input
4 6
2 4 3 5

Output
0
2 4 3 5

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(a)
counter = 0
for i in range(1, len(a)):
	if a[i - 1] + a[i] < k:
		temp = a[i]
		a[i] = k - a[i - 1]
		counter += a[i] - temp
print(counter)
for num in a:
	print(num, end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
add_walks = 0
for i in range(1, n):
	walks_needed = max(k - a[i] - a[i - 1], 0)
	a[i] += walks_needed
	add_walks += walks_needed
print(add_walks)
print(' '.join(map(str, a)))


from sys import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, input().split()))
dp1 = [0] * n
dp2 = [0] * n
for i in range(1, n):
	if a[i - 1] + dp1[i - 1] + a[i] < k:
		dp1[i] = k - (a[i - 1] + dp1[i - 1] + a[i])
for i in range(n - 2, -1, -1):
	if a[i + 1] + dp2[i + 1] + a[i] < k:
		dp2[i] = k - (a[i + 1] + dp2[i + 1] + a[i])
if sum(dp1) <= sum(dp2):
	ans = sum(dp1)
	b = [dp1[i] + a[i] for i in range(n)]
else:
	ans = sum(dp2)
	b = [dp2[i] + a[i] for i in range(n)]
print(ans)
print(*b)


import sys

def read():
	return sys.stdin.readline()
(n, k) = map(int, read().split())
a = list(map(int, read().split()))
sum = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		sum += k - a[i] - a[i + 1]
		a[i + 1] = k - a[i]
print(str(sum) + '\n' + ' '.join(map(str, a)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
for i in range(1, n):
	if a[i - 1] + a[i] < k:
		a[i] = k - a[i - 1]
print(sum(a) - total)
print(*a)


(n, k) = map(int, input().split())
walk_list = list(map(int, input().split()))
over_walk = 0
for i in range(n - 1):
	if walk_list[i] + walk_list[i + 1] < k:
		over_walk += k - walk_list[i] - walk_list[i + 1]
		walk_list[i + 1] = k - walk_list[i]
print(over_walk)
print(*walk_list)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
for i in range(n - 1):
	tmp = arr[i] + arr[i + 1]
	if tmp < k:
		arr[i + 1] += k - tmp
		cnt += k - tmp
print(cnt)
print(' '.join((str(i) for i in arr)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = [a[0]]
l = 0
for i in range(1, len(a)):
	if a[i] + c[-1] < k:
		l += k - c[-1] - a[i]
		c.append(k - c[-1])
	else:
		c.append(a[i])
print(l)
print(*c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	tmp = 0
	if a[i] + a[i + 1] < k:
		tmp = k - a[i] - a[i + 1]
		ans += tmp
	a[i + 1] = tmp + a[i + 1]
print(ans)
for i in range(n):
	if i != n - 1:
		print(a[i], end=' ')
print(a[n - 1])


from collections import defaultdict
import sys, os, math

def __starting_point():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		if arr[i] < k - arr[i - 1]:
			ans += k - arr[i - 1] - arr[i]
			arr[i] = k - arr[i - 1]
	print(ans)
	print(' '.join((str(i) for i in arr)))
__starting_point()


n_k = [int(a) for a in input().split(' ')]
a = [int(a) for a in input().split(' ')]
n = n_k[0]
k = n_k[1]
b = []
b.append(str(a[0]))
total_b = 0
for i in range(n - 1):
	total_b += max(k - (a[i] + a[i + 1]), 0)
	a[i + 1] += max(k - (a[i] + a[i + 1]), 0)
	b.append(str(a[i + 1]))
print(total_b)
print(' '.join(b))


import math
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for i in range(1, n):
	m = max(k - l[i - 1] - l[i], 0)
	l[i] = l[i] + m
	c += m
print(c)
print(*l)


a = list(map(int, input().split(' ')))
n = a[0]
k = a[1]
l = list(map(int, input().split(' ')))
total = 0
for i in range(0, n - 1):
	if l[i] + l[i + 1] < k:
		total = total + (k - l[i] - l[i + 1])
		l[i + 1] = l[i + 1] + (k - l[i] - l[i + 1])
print(total)
print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for i in range(1, n):
	if a[i - 1] + a[i] < k:
		s += k - (a[i - 1] + a[i])
		a[i] += k - (a[i - 1] + a[i])
print(s)
print(' '.join(map(str, a)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		c += k - (a[i] + a[i - 1])
		a[i] += k - (a[i] + a[i - 1])
print(c)
print(*a)


s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
for i in range(n):
	s[i] = int(s[i])
l = 0
for i in range(n - 1):
	if s[i] + s[i + 1] < k:
		l += k - s[i] - s[i + 1]
		s[i + 1] = k - s[i]
print(l)
for i in range(n):
	s[i] = str(s[i])
print(' '.join(s))


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
additional_walk = 0
for i in range(1, n):
	if walks[i] + walks[i - 1] < k:
		additional_walk += k - (walks[i] + walks[i - 1])
		walks[i] += k - (walks[i] + walks[i - 1])
print(additional_walk)
print(' '.join((str(i) for i in walks)))


(n, k) = map(int, input().split())
w = list(map(int, input().split()))
a = 0
b = [w[0]]
for i in range(1, n):
	t = w[i] + w[i - 1]
	if t < k:
		d = k - t
		a += d
		w[i] += d
	b.append(w[i])
print(a)
for i in b:
	print(i, end=' ')


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


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


(n, k) = map(int, input().split())
A = [int(s) for s in input().split()]
i = 0
d = 0
for i in range(len(A) - 1):
	while A[i] + A[i + 1] < k:
		A[i + 1] += 1
		d += 1
print(d)
for i in A:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
res = 0
for i in range(1, n):
	diff = k - (arr[i - 1] + arr[i])
	if diff <= 0:
		continue
	res += diff
	arr[i] += diff
print(res)
print(*arr)


(n, k) = map(int, input().split())
a = [int(k) for k in input().split()]
walk = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		walk += k - (a[i] + a[i - 1])
		a[i] = k - a[i - 1]
print(walk)
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(a)
if n == 1:
	print(0)
	print(a[0])
else:
	ans = 0
	for i in range(1, n):
		if a[i] + b[i - 1] < k:
			ans += k - (a[i] + b[i - 1])
			b[i] = a[i] + (k - (a[i] + b[i - 1]))
	print(ans)
	print(' '.join(map(str, b)))


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
ans = [arr[0]]
for i in range(1, n):
	ans.append(max(arr[i], k - ans[-1]))
print(sum(ans) - sum(arr))
print(*ans)


n_k = [int(x) for x in input().split()]
walks = [int(x) for x in input().split()]
dp = [0] * (n_k[0] + 1)
dp[0] = n_k[1]
for i in range(1, n_k[0] + 1):
	dp[i] = max(0, n_k[1] - walks[i - 1] - dp[i - 1]) + walks[i - 1]
print(sum(dp) - sum(walks) - dp[0])
result = ''
for x in dp[1:]:
	result += str(x) + ' '
print(result[:-1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
	if l[i - 1] + l[i] < k:
		cnt += k - l[i - 1] - l[i]
		l[i] = k - l[i - 1]
print(cnt)
for i in l:
	print(i, end=' ')


(n, k) = map(int, input().split())
l_d = list(map(int, input().split()))
t = 0
for i in range(1, n):
	if l_d[i - 1] + l_d[i] < k:
		t += k - (l_d[i] + l_d[i - 1])
		l_d[i] += k - (l_d[i] + l_d[i - 1])
print(t)
for d in l_d:
	print('%d' % d, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_list1 = sum(a)
for i in range(1, len(a)):
	if a[i] + a[i - 1] >= k:
		continue
	a[i] = k - a[i - 1]
print(sum(a) - sum_list1)
print(' '.join(map(str, a)))


(n, k) = map(int, input().split())
b = list(map(int, input().split()))
res = 0
for i in range(1, n):
	t = k - b[i] - b[i - 1]
	if t > 0:
		res += t
		b[i] += t
print(str(res) + '\n' + ' '.join(map(str, b)))


import sys
import math

def __main__():
	(n, k) = [int(e) for e in input().split()]
	a = [int(e) for e in input().split()]
	result = 0
	for i in range(1, n):
		s = a[i] + a[i - 1]
		if s < k:
			result += k - s
			a[i] += k - s
	print(result)
	for x in a:
		print(x, end=' ')
	print()
__main__()


def solve():
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	c = 0
	r = [0] * n
	r[0] = l[0]
	for i in range(1, n):
		x = k - l[i - 1]
		if x > l[i]:
			c += x - l[i]
			l[i] = x
		else:
			pass
	print(c)
	print(' '.join(map(str, l)))
solve()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
for i in range(1, n):
	if b[i] + b[i - 1] < k:
		b[i] += k - b[i] - b[i - 1]
print(sum(b) - sum(a))
print(' '.join(map(str, b)))


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
walks = 0
b = a[:]
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		b[i + 1] = k - a[i]
		walks += b[i + 1] - a[i + 1]
		a[i + 1] = b[i + 1]
print(walks)
print(' '.join((str(x) for x in b)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
b = []
for i in range(n):
	b.append(l[i])
sumoriginal = 0
for i in range(n):
	sumoriginal += l[i]
a = []
for i in range(n):
	if i % 2 == 0:
		if l[0] >= l[i]:
			a.append(l[0])
		else:
			a.append(l[i])
			l[0] = l[i]
	elif k - l[0] >= l[i]:
		a.append(k - l[0])
	else:
		a.append(l[i])
		l[0] = k - l[i]
sumnew = 0
for i in range(n):
	sumnew += a[i]
if sumnew > sumoriginal:
	print(sumnew - sumoriginal)
	print(*a)
else:
	print(0)
	print(*b)


def sol():
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	dp = [A[0]]
	for i in range(1, n):
		dp.append(k - dp[i - 1] if k - dp[i - 1] >= A[i] else A[i])
	s = 0
	for i in range(n):
		s += dp[i] - A[i]
	print(s)
	print(*dp, sep=' ')
sol()


inp = list(map(int, input().split(' ')))
walks = list(map(int, input().split(' ')))
n = inp[0]
k = inp[1]
total_modified_walks = 0
for i in range(1, len(walks)):
	total_walks_in_2d = walks[i] + walks[i - 1]
	if total_walks_in_2d < k:
		total_modified_walks += k - total_walks_in_2d
		walks[i] = k - walks[i - 1]
print(total_modified_walks)
print(' '.join([str(i) for i in walks]))


(a, b) = map(int, input().split())
x = [int(x) for x in input().split()]
s = 0
for i in range(a - 1):
	d = b - x[i]
	if d > x[i + 1]:
		p = x[i + 1]
		x[i + 1] = d
		s = s + d - p
print(s)
print(*x)


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
ans = [0] * n
ans[0] = ai[0]
for i in range(1, n):
	ans[i] = max(ai[i], k - ans[i - 1])
print(sum(ans) - sum(ai))
print(' '.join(list(map(str, ans))))


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for i in range(n - 1):
	s = l[i] + l[i + 1]
	if s < x:
		c = c + (x - s)
		l[i + 1] = l[i + 1] + (x - s)
print(c)
print(*l)


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, k) = mi()
b = li()
ans = 0
for i in range(n - 1):
	if b[i] + b[i + 1] >= k:
		continue
	else:
		l = b[i + 1]
		b[i + 1] = k - b[i]
		ans += b[i + 1] - l
print(ans)
print(*b)


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


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
count = 0
for i in range(a - 1):
	k = s[i] + s[i + 1]
	if b > k:
		l = max(s[i], s[i + 1])
		(s[i], s[i + 1]) = (s[i], s[i + 1] + b - k)
		count += b - k
print(count)
print(*s, sep=' ')


(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
newl = [l[0]]
ans = 0
for i in range(n - 1):
	if l[i] + l[i + 1] < k:
		ans += k - l[i] - l[i + 1]
		newl.append(k - l[i])
		l[i + 1] = k - l[i]
	else:
		newl.append(l[i + 1])
print(ans)
for i in newl[:-1]:
	print(i, end=' ')
print(newl[-1])


arr = [int(x) for x in input().split()]
n = arr[0]
k = arr[1]
arr_a = [int(x) for x in input().split()]
diff = 0
for i in range(n):
	x = arr_a[i]
	if i != 0:
		if k - arr_a[i - 1] > arr_a[i]:
			arr_a[i] = k - arr_a[i - 1]
	diff = diff + arr_a[i] - x
print(diff)
arr = ''
for i in range(n):
	arr = arr + str(arr_a[i]) + ' '
print(arr)


def main():
	(n, k) = map(int, input().split(' '))
	ip = [int(item) for item in input().split(' ')]
	prev = ip[0]
	additional = 0
	op = str(prev) + ' '
	for i in range(1, len(ip)):
		if ip[i] + prev < k:
			additional += k - ip[i] - prev
			ip[i] = k - prev
		prev = ip[i]
		op += str(ip[i]) + ' '
	print(additional)
	print(op)
main()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
if len(A) == 1:
	print(0)
	print(A[0])
else:
	an = 0
	for i in range(1, len(A)):
		if A[i] + A[i - 1] < K:
			an += K - A[i] - A[i - 1]
			A[i] += K - A[i] - A[i - 1]
	print(an)
	for a in A:
		print(a, end=' ')


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
additional = 0
for i in range(0, n - 1):
	walks = a[i] + a[i + 1]
	if walks < k:
		a[i + 1] += k - walks
		additional += k - walks
print(additional)
for x in a:
	print(x, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
for i in range(1, len(arr)):
	if arr[i - 1] + arr[i] < k:
		x = arr[i]
		arr[i] = k - arr[i - 1]
		cnt += arr[i] - x
print(cnt)
for i in range(len(arr)):
	print(arr[i], end=' ')


(n, k) = map(int, input().split())
m = [int(i) for i in input().split()]
d = 0
for i in range(1, n):
	if m[i] + m[i - 1] < k:
		d += k - m[i] - m[i - 1]
		m[i] += k - m[i] - m[i - 1]
print(d)
print(*m)


def main():
	try:
		while True:
			(n, k) = map(int, input().split())
			a = list(map(int, input().split()))
			prev = a[0]
			result = 0
			for (i, x) in enumerate(a[1:], 1):
				if prev + x < k:
					result += k - (prev + x)
					a[i] = prev = k - prev
				else:
					prev = x
			print(result)
			print(*a)
	except EOFError:
		pass
main()


from collections import Counter
import string
import math

def array_int():
	return [int(i) for i in input().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(input())
	if number_of_variables >= 2:
		return map(int, input().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
(n, k) = vary(2)
count = 0
num = array_int()
for i in range(n - 1):
	z = k - (num[i] + num[i + 1])
	if z <= 0:
		continue
	else:
		count += z
		num[i + 1] += z
print(count)
print(*num)


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = list(map(int, input().split()))
ans = 0
b = [a[0]]
output = str(b[0])
for i in range(1, n):
	ans += max(0, k - b[i - 1] - a[i])
	b.append(a[i] + max(0, k - b[i - 1] - a[i]))
	output += ' ' + str(b[i])
print(ans)
print(output)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
for i in range(1, n):
	extra = max(0, k - arr[i] - arr[i - 1])
	arr[i] += extra
	ans += extra
print(ans)
print(*arr)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
brr = arr.copy()
if len(arr) == 1:
	print(0)
	print(arr[0])
else:
	for i in range(1, len(arr)):
		have = arr[i] + arr[i - 1]
		addi = max(0, k - have)
		arr[i] += addi
	print(sum(arr) - sum(brr))
	print(' '.join(map(str, arr)))


(n, m) = list(map(int, input().split()))
p = list(map(int, input().split()))
y = 0
for x in range(n - 1):
	if p[x] + p[x + 1] < m:
		ta = m - p[x] - p[x + 1]
		p[x + 1] = p[x + 1] + ta
		y += ta
	else:
		pass
print(y)
print(*p)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
if n == 1:
	print(0)
	print(*l)
else:
	ans = 0
	for j in range(1, n):
		if l[j] + l[j - 1] < m:
			ans += m - (l[j] + l[j - 1])
			l[j] = m - l[j - 1]
	print(ans)
	print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
sc = 0
a.append(k)
for i in range(n):
	if a[i] + a[i + 1] < k:
		sc += k - (a[i] + a[i + 1])
		a[i + 1] += k - (a[i] + a[i + 1])
print(sc)
del a[n]
print(*a)


(n, k) = list(map(int, input().split()))
ls = list(map(int, input().split()))
dp = [[0, 0] for _ in range(n)]
for i in range(1, n):
	if ls[i] + ls[i - 1] + dp[i - 1][0] < k:
		ll = k - ls[i] - ls[i - 1] - dp[i - 1][0]
		dp[i][0] = ll
	dp[i][1] = dp[i][0] + dp[i - 1][1]
print(dp[n - 1][1])
print(' '.join(map(lambda x, y: str(x + y[0]), ls, dp)))


(n, k) = input().split()
n = int(n)
k = int(k)
count = 0
a = [int(x) for x in input().split()]
if n == 1:
	print(0)
	print(a[0])
elif len(a) % 2 == 0:
	for i in range(len(a) - 1):
		sum1 = a[i] + a[i + 1]
		if sum1 < k:
			a[i + 1] += k - sum1
			count += k - sum1
	print(count)
	for i in range(len(a)):
		print(a[i], end=' ')
else:
	for i in range(len(a) - 2):
		sum1 = a[i] + a[i + 1]
		if sum1 < k:
			a[i + 1] += k - sum1
			count += k - sum1
	if a[len(a) - 1] < a[len(a) - 3]:
		count += a[len(a) - 3] - a[len(a) - 1]
		a[len(a) - 1] = a[len(a) - 3]
	print(count)
	for i in range(len(a)):
		print(a[i], end=' ')


import math

def s():
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	ans = 0
	for i in range(1, n):
		if a[i - 1] + a[i] < k:
			temp = k - a[i - 1] - a[i]
			a[i] = temp + a[i]
			ans += temp
	print(ans)
	for i in range(n):
		print(a[i], end=' ')
	print()
s()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
minimum_sum = 0
for i in range(1, n):
	if arr[i] + arr[i - 1] >= k:
		pass
	else:
		val = k - arr[i - 1]
		if val < arr[i]:
			while val <= arr[i]:
				val = val + 1
		minimum_sum += val - arr[i]
		arr[i] = val
print(minimum_sum)
for i in range(n):
	print(arr[i], end=' ')
print()


def __starting_point():
	inp = input().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	a = [int(ch) for ch in input().split(' ')]
	addition = 0
	for i in range(1, len(a)):
		sum = a[i - 1] + a[i]
		new_sum = k - sum
		if new_sum < 0:
			new_sum = 0
		addition += new_sum
		a[i] = a[i] + new_sum
	print(addition)
	res = ''
	for c in a:
		res = res + str(c) + ' '
	print(res)
__starting_point()


from sys import stdin as fin
(n, k) = map(int, fin.readline().split())
arr = list(map(int, fin.readline().split()))
cnt = 0
for i in range(1, n):
	inc = k - (arr[i] + arr[i - 1])
	if inc > 0:
		arr[i] += inc
		cnt += inc
print(cnt)
print(' '.join((str(x) for x in arr)))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(1, n):
	sum_ = a[i] + a[i - 1]
	if sum_ < k:
		res += k - sum_
		a[i] += k - sum_
print(res)
print(*a)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	num = k - arr[i] - arr[i + 1]
	if num >= 0:
		arr[i + 1] += num
		ans += num
print(ans)
for val in arr:
	print(val, end=' ')


cnt = lambda s, i: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
(n, k) = f()
l = il()
dif = 0
for i in range(1, n):
	if l[i - 1] + l[i] < k:
		dif += k - (l[i] + l[i - 1])
		l[i] = k - l[i - 1]
print(dif)
print(*l)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
res = 0
for x in range(N - 1):
	if A[x] + A[x + 1] < K:
		res += K - (A[x] + A[x + 1])
		A[x + 1] += K - (A[x] + A[x + 1])
print(res)
print(' '.join(map(str, A)))


(a, b) = map(int, input().split())
ch = input()
l = ch.split()
s = 0
for i in range(1, a):
	if int(l[i]) + int(l[i - 1]) < b:
		s = s + (b - int(l[i]) - int(l[i - 1]))
		l[i] = str(b - int(l[i - 1]))
print(s)
for i in range(a):
	print(l[i], end=' ')


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		x = 1
		ans = 0
		while x < n:
			if x != n - 1:
				(t1, t2) = (0, 0)
				if l[x - 1] + l[x] < k:
					t1 = k - l[x] - l[x - 1]
				l[x] += max(t1, t2)
				ans += max(t1, t2)
			elif l[x - 1] + l[x] < k:
				ans += k - l[x - 1] - l[x]
				l[x] += k - l[x - 1] - l[x]
			x += 1
		print(ans)
		print(*l)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(d, k) = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
total = 0
for n in range(1, len(data)):
	min_ = k - data[n - 1] - data[n]
	if min_ > 0:
		data[n] += min_
		total += min_
print(total)
print(' '.join([str(x) for x in data]))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
k = 0
for i in range(n - 1):
	x = a[i] + a[i + 1]
	if x < m:
		k += m - x
		a[i + 1] += m - x
print(k)
print(*a)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
for i in range(1, n):
	a[i] = max(a[i], k - a[i - 1])
print(sum(a) - s)
print(*a)


(n, total_walks) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(0, n - 1):
	if l[i] + l[i + 1] < total_walks:
		diff = total_walks - (l[i] + l[i + 1])
		l[i + 1] = l[i + 1] + diff
		ans = ans + diff
print(ans)
print(*l)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
for i in range(n - 1):
	if arr[i] + arr[i + 1] < k:
		s = k - arr[i]
		count += s - arr[i + 1]
		arr[i + 1] = s
print(count)
for a in arr:
	print(a, end=' ')


(days, walks) = [int(i) for i in input().split()]
shedule = [int(i) for i in input().split()]
ans = [0] * days
for i in range(days - 1):
	if shedule[i] + shedule[i + 1] < walks:
		ans[i + 1] += walks - (shedule[i] + shedule[i + 1])
		shedule[i + 1] += walks - (shedule[i] + shedule[i + 1])
print(sum(ans))
for i in range(days):
	shedule[i] = str(shedule[i])
print(' '.join(shedule))


(n, k) = map(int, input().split())
a_vec = list(map(int, input().split()))
m = 0
for i in range(1, n):
	i_sum = a_vec[i - 1] + a_vec[i]
	if i_sum < k:
		m += k - i_sum
		a_vec[i] += k - i_sum
print(m)
print(' '.join(map(str, a_vec)))


(n, k) = [int(i) for i in input().strip().split()]
an = [int(i) for i in input().strip().split()]
bn = list()
bn.append(an[0])
awn = k - an[0]
count = 0
mi = 0
for i in range(1, len(an)):
	if an[i] < awn:
		mi = awn - an[i]
		count = count + mi
		bn.append(awn)
	else:
		mi = 0
		bn.append(an[i])
	awn = k - (an[i] + mi)
print(count)
for i in bn:
	print(i, end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
count = 0
required = 0
answer = []
for i in l:
	if required > i:
		count += required - i
		answer.append(required)
		required = k - required
	else:
		answer.append(i)
		required = k - i
print(count)
print(*answer, sep=' ')


(n, k) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
b = [a[0]]
p = 0
for j in range(1, n):
	if b[j - 1] + a[j] >= k:
		b.append(a[j])
		continue
	else:
		p += k - (b[j - 1] + a[j])
		b.append(a[j] + k - b[j - 1] - a[j])
print(p)
for j in range(n):
	print(b[j], end=' ')


(n, k) = map(int, input().split())
a = input().split()
b = []
number = 0
b.append(int(a[0]))
for i in range(len(a) - 1):
	b.append(int(a[i + 1]))
	while b[i] + b[i + 1] < k:
		b[i + 1] += 1
		number += 1
print(number)
for i in b:
	print(i, end=' ')


def find(a, k):
	b = []
	count = 0
	for p in range(len(a)):
		if p == 0:
			b.append(a[p])
			continue
		p1 = b[p - 1]
		p2 = a[p]
		d = k - (p1 + p2)
		if d <= 0:
			b.append(p2)
		else:
			count += d
			b.append(p2 + d)
	return (count, b)

def main():
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	k = a1[1]
	res = find(a2, k)
	print(res[0])
	print(' '.join(map(str, res[1])))

def test():
	print(find([2, 0, 1], 5))
main()


(n, k) = [int(x) for x in input().strip().split()]
walk = [int(x) for x in input().strip().split()]
count = 0
for i in range(n - 1):
	if walk[i + 1] + walk[i] < k:
		diff = k - walk[i + 1] - walk[i]
		walk[i + 1] = walk[i + 1] + diff
		count = count + diff
print(count)
for w in walk:
	print(w, end=' ')
print('')


def solve(arr, k):
	arr = arr
	ans = 0
	ans_arr = [arr[0]]
	for i in range(1, len(arr)):
		tmp = k - (arr[i] + ans_arr[i - 1])
		ans += max(0, tmp)
		ans_arr.append(max(0, tmp) + arr[i])
	print(ans)
	print(*ans_arr)
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
solve(arr, k)


t = input
p = print
r = range
(n, k) = map(int, t().split())
a = list(map(int, t().split()))
ans = sum(a)
for i in r(n - 1):
	if a[i] + a[i + 1] <= k:
		a[i + 1] += k - a[i + 1] - a[i]
ans = sum(a) - ans
p(ans)
p(' '.join(map(str, a)))


q = list(input().split(' '))
n = int(q[0])
k = int(q[1])
b = 0
a = list(input().split(' '))
a = [int(a[i]) for i in range(len(a))]
for i in range(len(a) - 1):
	c = a[i] + a[i + 1]
	if c < k:
		a[i + 1] += k - c
		b += k - c
print(b)
for i in range(len(a)):
	print(a[i], end=' ')


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	res = 0
	for i in range(1, len(a)):
		s = a[i] + a[i - 1]
		moar = 0
		if s < k:
			moar = k - s
		a[i] += moar
		res += moar
	print(res)
	print(' '.join(map(str, a)))
solve()


(n, k) = map(int, input().split())
walk = list(map(int, input().split()[:n]))
sum0 = sum(walk)
for i in range(n - 1):
	if walk[i] + walk[i + 1] < k:
		walk[i + 1] += k - walk[i] - walk[i + 1]
print(sum(walk) - sum0)
print(*walk)


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
i = 1
c = sum(a)
while i < x:
	a[i] = max(a[i], y - a[i - 1])
	i += 1
print(sum(a) - c)
print(*a)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
su = 0
for i in range(n - 1):
	if l[i] + l[i + 1] < k:
		su += k - l[i] - l[i + 1]
		l[i + 1] += k - l[i] - l[i + 1]
print(su)
print(*l)


(k, r) = [int(s) for s in input().split()]
map1 = list(map(int, input().split()))
s = 0
for i in range(1, len(map1)):
	if map1[i] + map1[i - 1] <= r:
		s += r - (map1[i] + map1[i - 1])
		map1[i] += r - (map1[i] + map1[i - 1])
print(s)
for i in map1:
	print(i, end=' ')


d = input().split()
n = int(d[0])
k = int(d[1])
d = input().split()
d = [int(x) for x in d]
S = 0
for i in range(n - 1):
	if d[i] + d[i + 1] < k:
		S += k - (d[i] + d[i + 1])
		d[i + 1] += k - (d[i] + d[i + 1])
print(S)
for i in d:
	print(i, end=' ')


(n, k) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
s = l
if len(l) == 1:
	print(0)
	print(l[0])
else:
	c = 0
	for i in range(len(l) - 1):
		if l[i] + l[i + 1] < k:
			c += k - (l[i] + l[i + 1])
			l[i + 1] = l[i + 1] + (k - (l[i] + l[i + 1]))
		else:
			continue
	print(c)
	print(*l)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = []
count = 0
for i in range(1, n):
	if x[i] + x[i - 1] < k:
		new = k - x[i - 1]
		count += new - x[i]
		x[i] = new
print(count)
for i in x:
	print(i, end=' ')


(n, k) = map(int, input().split())
(*l,) = map(int, input().split())
a = 0
for i in range(1, n):
	two = l[i] + l[i - 1]
	if two < k:
		l[i] += k - two
		a += k - two
print(str(a) + '\n' + ' '.join(map(str, l)))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
if n == 1:
	print(0)
	print(a[0])
else:
	c = 0
	for i in range(1, n):
		if a[i] + a[i - 1] < k:
			temp = k - (a[i - 1] + a[i])
			a[i] += temp
			c += temp
	print(c)
	print(*a)


(n, k) = str(input()).split()
(n, k) = (int(n), int(k))
line = str(input()).split()
line = [int(t) for t in line]
v = 0
for i in range(1, n):
	s = line[i] + line[i - 1]
	if s < k:
		v += k - s
		line[i] = k - line[i - 1]
print(v)
line = [str(t) for t in line]
print(' '.join(line))


import sys
(num_days, num_walks) = map(int, sys.stdin.readline().split())
planned_walks = list(map(int, sys.stdin.readline().split()))
total_to_add = 0
for walk_pos in range(1, num_days):
	to_add = max(0, num_walks - planned_walks[walk_pos] - planned_walks[walk_pos - 1])
	total_to_add += to_add
	planned_walks[walk_pos] += to_add
print(total_to_add)
print(' '.join(map(str, planned_walks)))


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
inc = 0
for i in range(1, len(a)):
	prev = a[i] + a[i - 1]
	if prev < m:
		a[i] += m - prev
		inc += m - prev
print(inc)
print(' '.join([str(i) for i in a]))


import math
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = 0
for i in range(a[0] - 1):
	if b[i] + b[i + 1] < a[1]:
		d += -b[i] - b[i + 1] + a[1]
		b[i + 1] += a[1] - b[i + 1] - b[i]
print(d)
for i in range(a[0]):
	print(b[i], end=' ')


(n, k) = map(int, input().split())
walk = list(map(int, input().split()))
add = 0
for i in range(1, n):
	tot = walk[i - 1] + walk[i]
	if tot < k:
		add += k - tot
		walk[i] += k - tot
print(add)
for i in walk:
	print(i, end=' ')


def f(n, k, a):
	count = 0
	for i in range(1, n):
		walkes_completed = a[i] + a[i - 1]
		if walkes_completed < k:
			count += k - walkes_completed
			a[i] += k - walkes_completed
	print(count)
	print(a[0], end='')
	for i in range(1, n):
		print('', a[i], end='')
	print()
	return count
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f(n, k, a)


(n, k) = input().split()
(n, k) = (int(n), int(k))
lia = list(map(int, input().split()))
cn = 0
for i in range(n - 1):
	if lia[i] + lia[i + 1] < k:
		at = k - lia[i] - lia[i + 1]
		lia[i + 1] += k - lia[i] - lia[i + 1]
		cn += at
print(cn)
print(' '.join((str(i) for i in lia)))


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2, floor
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 10 ** 9 + 7

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
Arr = get_array()
result = [0] * n
result[0] = Arr[0]
for i in range(1, n):
	if Arr[i] + result[i - 1] >= k:
		result[i] = Arr[i]
	else:
		result[i] = k - result[i - 1]
count = 0
for i in range(n):
	count += result[i] - Arr[i]
print(count)
print(*result, sep=' ')


ii = lambda : int(input())
iin = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
(n, m) = iin()
a = il()
if n == 1:
	ans = 0
else:
	ans = 0
	for i in range(1, n):
		if a[i] + a[i - 1] < m:
			ans += m - a[i] - a[i - 1]
			a[i] = m - a[i - 1]
print(ans)
print(*a)


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
count = 0
for i in range(1, n):
	if a[i] + a[i - 1] < m:
		count += m - a[i] - a[i - 1]
		a[i] = m - a[i - 1]
print(count)
print(' '.join(map(str, a)))


(n, k) = [int(i) for i in input().split()]
ar = [int(i) for i in input().split()]
suma = 0
for i in range(n - 1):
	ip = max(ar[i + 1], -ar[i] + k)
	suma += ip - ar[i + 1]
	ar[i + 1] = ip
print(suma)
for i in ar:
	print(i, end=' ')


(n, k) = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
c = 0
ans = [q[0]]
for i in range(1, n):
	ans.append(q[i])
	t = k - ans[i - 1] - q[i]
	if t >= 0:
		c += t
		ans[i] += t
print(c)
print(' '.join(map(str, ans)))


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = 0
for i in range(1, n):
	if a[i - 1] + a[i] < k:
		c += k - (a[i - 1] + a[i])
		a[i] += k - (a[i - 1] + a[i])
print(c)
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
arr.append(k)
arr.insert(0, k)
extra = 0
for i in range(1, n + 1):
	if arr[i] + arr[i - 1] < k:
		temp = arr[i]
		arr[i] = k - arr[i - 1]
		extra += k - arr[i - 1] - temp
print(extra)
print(*arr[1:-1])


n = [int(i) for i in input().split()]
days = [int(i) for i in input().split()]
k = 0
for i in range(n[0] - 1):
	if days[i] + days[i + 1] < n[1]:
		k += n[1] - days[i + 1] - days[i]
		days[i + 1] += n[1] - days[i + 1] - days[i]
for i in range(n[0]):
	days[i] = str(days[i])
print('{}\n{}'.format(k, ' '.join(days)))


def hren():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	input_list = input().split(' ')
	a = [int(x.strip()) for x in input_list]
	change_num = 0
	for i in range(n - 1):
		neighbour_sum = a[i] + a[i + 1]
		if neighbour_sum < k:
			change_num += k - neighbour_sum
			a[i + 1] += k - neighbour_sum
	print(change_num)
	for each in a:
		print(each, end=' ')
hren()


(n, k) = map(int, input().split())
walks = [i for i in map(int, input().split())]
before = sum(walks)
for (idx, w) in enumerate(walks):
	if idx == len(walks) - 1:
		continue
	val = walks[idx] + walks[idx + 1]
	if val < k:
		walks[idx + 1] = k - walks[idx]
print(sum(walks) - before)
print(' '.join([str(i) for i in walks]))


ins = input().strip().split(' ')
(n, k) = (int(ins[0]), int(ins[1]))
a = [int(i) for i in input().strip().split(' ')]
b = []
small = 0
b.append(a[0])
for i in range(n - 1):
	diff = k - (b[i] + a[i + 1])
	if diff > 0:
		small += diff
		b.append(a[i + 1] + diff)
	else:
		b.append(a[i + 1])
print(small)
for i in range(len(b)):
	print(b[i], end=' ')


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
total_diff = 0
b = [0 for _ in range(len(a))]
b[0] = a[0]
for i in range(1, len(a)):
	diff = max(k - a[i] - b[i - 1], 0)
	b[i] = a[i] + diff
	total_diff += diff
print(total_diff)
print(' '.join(map(str, b)))


def solve(n, k, a):
	s = 0
	prev = k
	out = ''
	for i in range(n):
		x = max(0, max(0, k - prev) - a[i])
		s += x
		prev = a[i] + x
		out = out + str(prev) + ' '
	print(s)
	print(out)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
solve(n, k, a)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = a[:]
for i in range(1, n):
	a[i] += max(0, k - a[i] - a[i - 1])
print(sum(a) - sum(b))
print(*a, sep=' ')


(n, k) = map(int, input().split())
l = [*map(int, input().split())]
count = 0
for i in range(1, n):
	m = k - (l[i] + l[i - 1])
	if m > 0:
		count += m
		l[i] += m
print(count)
for i in l:
	print(i, end=' ')


a = input()
a = a.split()
n = int(a[0])
k = int(a[1])
a = input()
a = a.split()
ans = 0
for i in range(0, n):
	a[i] = int(a[i])
for i in range(1, n):
	if a[i - 1] + a[i] < k:
		ans += k - a[i - 1] - a[i]
		a[i] = k - a[i - 1]
print(ans)
for i in range(0, n):
	print(a[i], end=' ')


def read_number_line():
	return [int(i) for i in input().split()]
(n, k) = read_number_line()
a = read_number_line()
total_additional = 0
b = [0] * n
b[0] = a[0]
for i in range(1, n):
	additional = 0
	if a[i] + a[i - 1] < k:
		additional = k - a[i - 1] - a[i]
	b[i] = a[i] + additional
	a[i] = b[i]
	total_additional += additional
print(total_additional)
print(*b)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
add = 0
total = 0
l.append(0)
for i in range(n):
	l[i] += add
	total += add
	add = 0
	x = l[i] + l[i + 1]
	if x < k:
		add = k - x
print(total)
print(*l[:n])


import math
import sys
import cmath
import string
import bisect
from itertools import combinations, permutations
from queue import Queue, LifoQueue, PriorityQueue
from collections import deque, Counter
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0 for i in range(len(a))]
sum = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		sum += k - a[i] - a[i + 1]
		a[i + 1] = k - a[i]
print(sum)
for i in range(n):
	print(a[i], end=' ')


(n, k) = map(int, input().split())
A = [int(a) for a in input().split()]
K = A[0]
extras = [0]
for a in A[1:]:
	r = k - (K + a)
	if r < 0:
		r = 0
	extras.append(r)
	K = a + r
print(sum(extras))
total = [extras[i] + A[i] for i in range(n)]
for t in total:
	print(t, end=' ')
print()


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
sum = 0
for i in range(0, len(a) - 1):
	if a[i] + a[1 + i] < d:
		sum = sum + abs(a[i + 1] + a[i] - d)
		a[i + 1] += abs(a[i + 1] + a[i] - d)
print(sum)
print(*a, sep=' ')


def main():
	(n, k) = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	total_extra = 0
	prev = k
	for i in range(n):
		prev = b[i - 1] if i >= 1 else k
		extra = k - (prev + b[i])
		if extra > 0:
			total_extra += extra
			b[i] += extra
	print(total_extra)
	print(' '.join([str(i) for i in b]))
main()


nk = list(map(int, input().split()))
a = list(map(int, input().split()))
b = 0
for i in range(1, nk[0]):
	if a[i] + a[i - 1] < nk[1]:
		b += nk[1] - (a[i] + a[i - 1])
		a[i] += nk[1] - (a[i] + a[i - 1])
print(b)
print(*a)


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
(b, mb) = ([0 for _ in range(n)], [1000 for _ in range(n)])
firsttime = True
b[0] = a[0]
while b[0] <= k or firsttime:
	firsttime = False
	for i in range(1, n):
		b[i] = max(k - b[i - 1], a[i])
	if sum(b) < sum(mb):
		mb = [b[i] for i in range(n)]
	b[0] += 1
print(sum(mb) - sum(a))
for e in mb:
	print(e, end=' ')


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
t = 0
for i in range(n - 1):
	if walks[i] + walks[i + 1] < k:
		t += k - (walks[i] + walks[i + 1])
		walks[i + 1] += k - (walks[i] + walks[i + 1])
print(t)
print(*walks)


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def num(str=None):
	str = str or line()
	return float(str) if '.' in str else int(str)

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(num, o or split()))

def mainloop(tcid=1):
	(n, k) = nums()
	a = nums()
	dt = 0
	for ii in range(1, n):
		a1 = a[ii - 1]
		aa = a[ii]
		bb = max(aa, k - a1)
		dt += bb - aa
		a[ii] = bb
	print(dt)
	print(*a)
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


(n, k) = input().split()
(n, k) = (int(n), int(k))
l = list(map(int, input().split()))
Sum = sum(l)
for i in range(1, n):
	l[i] = max(l[i], k - l[i - 1])
print(sum(l) - Sum)
print(*l)


(n, p) = map(int, input().split())
m = list(map(int, input().split()))
mas = []
i = 0
s = 0
while i < len(m):
	mas.append(m[i])
	i += 1
i = 1
while i < len(mas):
	if mas[i] + mas[i - 1] < p:
		s += p - mas[i - 1] - mas[i]
		mas[i] = p - mas[i - 1]
	i += 1
print(s)
for i in mas:
	print(i, end=' ')


(n, k) = map(int, input().split())
A = [*map(int, input().split())]
add = 0
for i in range(1, len(A)):
	if A[i - 1] + A[i] < k:
		a = k - (A[i - 1] + A[i])
		A[i] += a
		add += a
print(add)
print(' '.join(map(str, A)))


import math, sys, re, itertools, pprint
(ri, rai) = (lambda : int(input()), lambda : list(map(int, input().split())))
(n, k) = rai()
a = rai()
p = a[0]
res = 0
for i in range(1, n):
	if p + a[i] < k:
		res += k - p - a[i]
		a[i] += k - p - a[i]
	p = a[i]
print(res)
print(' '.join(map(str, a)))


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(a) == 1:
		print(0)
		print(*a)
		return
	ans = 0
	for i in range(1, n):
		s1 = a[i - 1] + a[i]
		rem = max(0, k - s1)
		a[i] += rem
		ans += rem
	print(ans)
	print(*a)
main()


l1 = [int(x) for x in input().split()]
(n, k) = (l1[0], l1[1])
l2 = [int(x) for x in input().split()]
ans = 0
for x in range(len(l2) - 1):
	if l2[x] + l2[x + 1] < k:
		ans += k - l2[x] - l2[x + 1]
		l2[x + 1] = k - l2[x]
print(ans)
print(*l2)


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


(a, b) = map(int, input().split())
(*c,) = map(int, input().split())
d = 0
for i in range(1, a):
	e = max(0, b - c[i - 1] - c[i])
	d += e
	c[i] += e
print(d)
print(' '.join(map(str, c)))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
for (i, j) in enumerate(arr):
	if i >= 1:
		if j + arr[i - 1] < k:
			ans += k - (arr[i - 1] + j)
			arr[i] += k - (arr[i - 1] + j)
print(ans)
for i in arr:
	print(i, end=' ')
print()


from copy import deepcopy
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
additional_hours = 0
b = deepcopy(a)
for i in range(1, n):
	total = b[i] + b[i - 1]
	if total < k:
		more = k - total
		b[i] += more
		additional_hours += more
print(additional_hours)
print(' '.join([str(x) for x in b]))


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
add = 0
for i in range(len(a) - 1):
	if a[i] + a[i + 1] < k:
		add += k - (a[i] + a[i + 1])
		a[i + 1] += k - (a[i] + a[i + 1])
print(add)
for i in a:
	print(i, end=' ')


line1 = input()
line2 = input()
inp1_list = line1.split(' ')
plan = [int(x) for x in line2.split()]
n = int(inp1_list[0])
k = int(inp1_list[1])
result = [plan[0]]
if n == 1:
	result[0] = plan[0]
else:
	for i in range(0, n - 1):
		if result[i] + plan[i + 1] < k:
			result.append(k - result[i])
		else:
			result.append(plan[i + 1])
days_new = sum([result[i] - plan[i] for i in range(n)])
str_result = ' '.join((str(result[i]) for i in range(n)))
print(days_new)
print(str_result)


(n, k) = list(map(lambda x: int(x), input().split(' ')))
nums = [k]
nums += list(map(lambda x: int(x), input().split(' ')))
nums.append(k)
sum_n = 0
i = 1
while i < n:
	if nums[i] + nums[i + 1] < k:
		sum_n += k - nums[i] - nums[i + 1]
		nums[i + 1] += k - nums[i] - nums[i + 1]
	i += 1
print(sum_n)
for (i, num) in enumerate(nums):
	if i == 0 or i == len(nums) - 1:
		continue
	print(num, ' ', sep='', end='')


import sys
(n, k) = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = []
b.append(a[0])
ans = 0
for i in range(1, len(a)):
	if b[i - 1] + a[i] >= k:
		b.append(a[i])
	else:
		b.append(k - b[i - 1])
		ans += k - b[i - 1] - a[i]
print(ans)
print(' '.join([str(i) for i in b]))


def fun(n, k, l):
	for i in range(n - 1):
		if l[i] + l[i + 1] < k:
			return False
	return True
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if n == 1 or fun(n, k, l):
	print(0)
	print(*l)
else:
	c = 0
	for i in range(1, n):
		r = k - l[i - 1] - l[i]
		if r > 0:
			l[i] += r
			c += r
	print(c)
	print(*l)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
t = 0
for i in range(1, n):
	z = k - a[i - 1] - a[i]
	if z < 0:
		z = 0
	else:
		t += z
		a[i] = k - a[i - 1]
print(t)
for i in range(n):
	print(a[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
sum_ = sum(l)
for i in range(1, n):
	l[i] += max(0, k - (l[i] + l[i - 1]))
print(sum(l) - sum_)
print(*l)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
cnt = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		cnt += k - (a[i] + a[i - 1])
		a[i] = a[i] + (k - (a[i] + a[i - 1]))
print(cnt)
print(' '.join((str(i) for i in a)))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(nb_days, min_walk) = read_ints()
walks = read_ints()
valid = [0] * nb_days
valid[0] = walks[0]
for i in range(1, nb_days):
	valid[i] = max(walks[i], min_walk - valid[i - 1])
print(sum(valid) - sum(walks))
print(*valid)


(X, Days, SUM) = (list(map(int, input().split())), list(map(int, input().split())), 0)
(Additional, Last) = ([0], Days[0])
for i in range(1, X[0]):
	Diff = max(0, X[1] - Days[i - 1] - Days[i])
	SUM += Diff
	Days[i] += Diff
print(SUM)
print(*Days)


def solve(n, k, s):
	dp = [0] * n
	cnt = 0
	dp[0] = s[0]
	for i in range(1, n):
		if dp[i - 1] + s[i] < k:
			dp[i] = k - dp[i - 1]
			cnt += dp[i] - s[i]
		else:
			dp[i] = s[i]
			continue
	print(cnt)
	print(' '.join(map(str, dp)))
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
solve(n, k, ar)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
sm = 0
for i in range(1, n):
	if l[i] + l[i - 1] >= k:
		continue
	else:
		r = k - l[i] - l[i - 1]
		l[i] += r
		sm += r
print(sm)
print(*l)


s = input().split()
n = int(s[0])
k = int(s[1])
a = [int(x) for x in input().split()]
dp = []
ans = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		ans += k - a[i - 1] - a[i]
		a[i] = k - a[i - 1]
print(ans)
for i in range(n):
	print(a[i], end=' ')


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, K) = map(int, input().split())
A = [int(x) for x in input().split()]
t = sum(A)
for i in range(1, N):
	A[i] = max(A[i], K - A[i - 1])
print(sum(A) - t)
print(' '.join(map(str, A)))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
ans = 0
for i in range(1, len(a)):
	walks = a[i] + a[i - 1]
	if walks < k:
		ans += k - walks
		a[i] += k - walks
print(ans)
print(*a)


import sys
initline = sys.stdin.readline().strip().replace('\n', '').split()
walks = sys.stdin.readline().strip().replace('\n', '').split()
walksAdded = []
for i in walks:
	walksAdded.append(0)
i = 0
j = 1
while True:
	if len(walks) == 1:
		walksAdded[i] = 0
		break
	else:
		if int(walks[j]) + int(walks[i]) < int(initline[1]):
			walksAdded[j] = int(initline[1]) - (int(walks[i]) + int(walks[j]))
			walks[j] = str(int(walks[j]) + walksAdded[j])
		j += 1
		i += 1
		if j > len(walks) - 1:
			break
string = str(walks[0])
for i in range(1, len(walks)):
	string += ' '
	string += walks[i]
count = 0
for i in walksAdded:
	count += i
print(count)
print(string)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
for i in range(1, n):
	b[i] = max(0, k - (a[i - 1] + a[i] + b[i - 1]))
print(sum(b))
for i in range(n):
	print(a[i] + b[i], end=' ')


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
ret = 0
for i in range(len(walks) - 1):
	ret += max(0, k - walks[i] - walks[i + 1])
	walks[i + 1] += max(0, k - walks[i] - walks[i + 1])
print(ret)
for w in walks:
	print(w, end=' ')


(n, walks) = map(int, input().split())
arr = [int(i) for i in input().split()]
count = 0
if n % 2 != 0:
	for i in range(n - 1):
		if arr[i] + arr[i + 1] < walks:
			count += walks - (arr[i] + arr[i + 1])
			arr[i + 1] += walks - (arr[i] + arr[i + 1])
	print(str(count) + '\n' + ' '.join((str(i) for i in arr)))
else:
	for i in range(n - 1):
		if arr[i] + arr[i + 1] < walks:
			count += walks - (arr[i] + arr[i + 1])
			arr[i + 1] += walks - (arr[i] + arr[i + 1])
	print(str(count) + '\n' + ' '.join((str(i) for i in arr)))


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
res = 0
for i in range(1, n):
	if lst[i] + lst[i - 1] < k:
		res += k - (lst[i] + lst[i - 1])
		lst[i] += k - (lst[i] + lst[i - 1])
print(res)
print(*lst)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] <= val:
			ans = mid + 1
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def odd(n, ans, s):
	if n % 2 != 0 or n in s:
		return ans
	else:
		s.add(n)
		return odd(n // 2, ans + 1, s)
(n, k) = map(int, stdin.readline().split(' '))
l = list(map(int, stdin.readline().split(' ')))
if n == 1:
	print(0)
	print(l[0])
else:
	c = 0
	for i in range(1, n):
		if l[i] + l[i - 1] >= k:
			continue
		else:
			c += k - l[i] - l[i - 1]
			l[i] += k - l[i] - l[i - 1]
	print(c)
	print(*l)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for i in range(1, n):
	if l[i] + l[i - 1] < k:
		mx = max(0, k - l[i] - l[i - 1])
		c += mx
		l[i] += mx
print(c)
print(*l)


(n, k) = map(int, input().split())
(l, x) = ([k], 0)
for (a, b) in zip(l, map(int, input().split())):
	c = k - a
	if b < c:
		x += c - b
		b = c
	l.append(b)
print(x)
print(*l[1:])


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
g = 0
for i in range(1, n):
	if s[i - 1] + s[i] < k:
		g += k - s[i - 1] - s[i]
		s[i] += k - s[i - 1] - s[i]
print(g)
print(*s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
Min = 0
for i in range(1, n):
	Min += max(0, k - a[i] - a[i - 1])
	a[i] += max(0, k - a[i] - a[i - 1])
print(Min)
print(*a)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
a = []
a.append(arr[0])
for i in range(1, n):
	req = 0
	if arr[i - 1] + arr[i] < k:
		req = k - arr[i - 1]
		ans += abs(arr[i] - req)
		arr[i] = req
		a.append(req)
	else:
		a.append(arr[i])
print(ans)
print(*a)


(n, ll) = map(int, input().split())
(*l,) = map(int, input().split())
m = 0
for x in range(1, n):
	if l[x - 1] + l[x] < ll:
		a = ll - l[x - 1] - l[x]
		m += a
		l[x] += a
print(m)
print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
old = sum(a)
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		a[i] += k - (a[i] + a[i - 1])
print(max(sum(a) - old, 0))
print(*a)


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = a.copy()
for i in range(1, n):
	if b[i] + b[i - 1] < k:
		b[i] = k - b[i - 1]
print(sum(b) - sum(a))
print(*b)


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
answer = 0
for i in range(1, len(a)):
	total = a[i - 1] + a[i]
	if total < k:
		answer += k - total
		a[i] += k - total
print(answer)
for x in a:
	print(str(x) + ' ', end='')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
coun = 0
for j in range(1, n):
	if a[j] >= k - a[j - 1]:
		continue
	x = k - a[j - 1]
	coun += x - a[j]
	a[j] = x
print(coun)
for y in a:
	print(y, end=' ')
print('')


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


import sys
(n, k) = map(int, sys.stdin.readline().split())
l = list(map(int, sys.stdin.readline().split()))
cur = l[0]
ans = [l[0]]
for i in range(1, n):
	if cur + l[i] < k:
		ans.append(k - cur)
		cur = k - cur
	else:
		cur = l[i]
		ans.append(l[i])
print(sum(ans) - sum(l))
print(*ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(len(a) - 1):
	if a[i] + a[i + 1] < k:
		d = k - a[i] - a[i + 1]
		ans += d
		a[i + 1] += d
print(ans)
print(*a)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
cnt = 0
for i in range(0, n - 1):
	sum = a[i] + a[i + 1]
	if sum < k:
		a[i + 1] += k - sum
		cnt += k - sum
print(cnt)
print(*a)


(n, k) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
sayac = 0
for x in range(len(arr) - 1):
	while arr[x] + arr[x + 1] < k:
		if arr[x] > arr[x + 1]:
			arr[x + 1] += 1
			sayac += 1
		else:
			arr[x + 1] += 1
			sayac += 1
print(sayac)
for x in arr:
	print(x, end=' ')


(n, k) = [int(x) for x in input().split()]
plan = [int(x) for x in input().split()]
addition = 0
for i in range(n - 1):
	if plan[i] + plan[i + 1] < k:
		addition += k - plan[i] - plan[i + 1]
		plan[i + 1] += k - plan[i] - plan[i + 1]
print(addition)
for i in plan:
	print(i, end=' ')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, k) = M()
l = L()
x = k
ans = 0
for i in range(n):
	if x + l[i] < k:
		ans += k - (x + l[i])
		l[i] += k - (x + l[i])
		x = l[i]
	else:
		x = l[i]
print(ans)
print(*l)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
addn = 0
for i in range(len(a) - 1):
	if a[i] + a[i + 1] < k:
		ext = k - a[i] - a[i + 1]
		addn += ext
		a[i + 1] += ext
print(addn)
print(*a)


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
inc = sum(walks)
if n == 1:
	pass
elif n == 2:
	if inc < k:
		walks[-1] += k - inc
else:
	for i in range(1, n - 1):
		if walks[i] + walks[i - 1] < k:
			walks[i] += k - (walks[i] + walks[i - 1])
		if walks[i] + walks[i + 1] < k:
			walks[i + 1] += k - (walks[i] + walks[i + 1])
print(sum(walks) - inc)
print(*walks)


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
extra = 0
curr = 0
for i in range(1, n):
	curr = walks[i - 1]
	if curr + walks[i] < k:
		temp = k - curr - walks[i]
		extra += temp
		walks[i] += temp
print(extra)
print(*walks)


from sys import stdin
from collections import defaultdict
input = lambda : stdin.readline().strip()
(n, k) = [int(i) for i in input().split()]
lst = list(map(int, input().split()))
sum1 = 0
for i in range(1, n):
	if lst[i] + lst[i - 1] < k:
		d = k - (lst[i] + lst[i - 1])
		lst[i] += d
		sum1 += d
print(sum1)
print(*lst)


(n, k) = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
ans = 0
for i in range(2, n + 1):
	if a[i] + a[i - 1] < k:
		ans += max(k - a[i - 1] - a[i], 0)
		a[i] = max(k - a[i - 1], 0)
print(ans)
for i in range(1, n + 1):
	print(a[i], end=' ')


from sys import stdin
(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
ans = 0
for i in range(1, len(arr)):
	tmp = k - arr[i] - arr[i - 1]
	if tmp > 0:
		arr[i] += tmp
		ans += tmp
print(str(ans) + '\n' + ' '.join(map(str, arr)))


r = 0
r1 = 0
(n, k) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
for i in range(0, n, 1):
	if i >= 1:
		if arr[i] + arr[i - 1] < k:
			r = abs(k - (arr[i] + arr[i - 1]))
			arr[i] += r
			r1 += r
print(r1)
for i in range(0, n, 1):
	print(arr[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
x = 1
ans = 0
if n == 1:
	print(0)
	print(l[0])
else:
	while x < n:
		if l[x] + l[x - 1] < k:
			ans += k - (l[x] + l[x - 1])
			l[x] = l[x] + k - (l[x] + l[x - 1])
		x += 1
	print(ans)
	for _ in l:
		print(_, end=' ')


l = list(map(int, input().split()))
n = l[0]
k = l[1]
l = list(map(int, input().split()))
o = 0
w = []
for i in range(len(l)):
	w.append(l[i])
if len(l) == 1:
	print(0)
	print(l[0])
else:
	for i in range(len(l)):
		if i == 0:
			if l[0] + l[1] < k:
				l[1] = l[1] + abs(k - (l[0] + l[1]))
		elif i == len(l) - 1:
			if l[i - 1] + l[i] < k:
				l[i - 1] = l[i - 1] + abs(k - (l[i] + l[i - 1]))
		elif l[i] + l[i + 1] < k:
			l[i + 1] = l[i + 1] + abs(k - (l[i] + l[i + 1]))
	o = 0
	for i in l:
		o += i
	for i in w:
		o -= i
	s = ''
	for i in l:
		s = s + str(i)
		s = s + ' '
	print(o)
	print(s)


(x, y) = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]
a = z[0]
b = 0
for i in range(1, x):
	if y > a + z[i]:
		b += y - a - z[i]
		z[i] += y - a - z[i]
	a = z[i]
print(b)
for i in z:
	print(i, end=' ')


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < m:
		hey = m - (a[i] + a[i + 1])
		a[i + 1] += hey
		ans += hey
print(ans)
print(*a)


(n, k) = map(int, input().split())
a = [k] + list(map(int, input().split())) + [k]
c = 0
for i in range(1, len(a) - 1):
	add = max(k - a[i] - a[i - 1], 0)
	c += add
	a[i] += add
print(c)
print(*a[1:-1])


lst = [int(i) for i in input().split()]
num_of_days = lst[0]
dog_limit = lst[1]
walks_in_days = [int(i) for i in input().split()]
prev_day = walks_in_days[0]
total_diff = 0
for i in range(1, num_of_days):
	today = walks_in_days[i]
	if today + prev_day < dog_limit:
		diff = dog_limit - today - prev_day
		walks_in_days[i] += diff
		prev_day = walks_in_days[i]
		total_diff += diff
		continue
	prev_day = walks_in_days[i]
print(total_diff)
[print(i, end=' ') for i in walks_in_days]


(n, k) = list(map(int, input().split()))
days = input().split()
changes = 0
for day in range(n - 1):
	day1 = int(days[day])
	day2 = int(days[day + 1])
	day2p = k - (day1 + day2)
	if day2p > 0:
		changes += day2p
		days[day + 1] = str(day2 + day2p)
print(changes)
print(' '.join(days))


def main():
	(n, k) = map(int, input().split())
	walks = [k]
	walks.extend(map(int, input().split()))
	walks.append(k)
	add_walks = 0
	for i in range(n + 1):
		nwalks = walks[i] + walks[i + 1]
		if nwalks < k:
			walks[i + 1] += k - nwalks
			add_walks += k - nwalks
	print(add_walks)
	for j in range(1, n + 1):
		if j < n:
			print(walks[j], end=' ')
		else:
			print(walks[j])
main()


(a, b) = map(int, input().split())
ar = list(map(int, input().split()))
ans = 0
for i in range(a - 1):
	if ar[i] + ar[i + 1] < b:
		ans += b - (ar[i] + ar[i + 1])
		ar[i + 1] += b - (ar[i] + ar[i + 1])
print(ans)
for i in ar:
	print(i, end=' ')


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


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
s = sum(arr)
for i in range(1, len(arr)):
	if arr[i] + arr[i - 1] < k:
		arr[i] = k - arr[i - 1]
sn = sum(arr)
print(sn - s)
for i in arr:
	print(i, end=' ')


(n, k) = input().split(' ')
a = input().split(' ')
count = 0
for i in range(1, len(a)):
	if int(a[i - 1]) + int(a[i]) < int(k):
		add = int(k) - int(a[i - 1]) - int(a[i])
		a[i] = int(a[i]) + add
		count += add
print(count)
ans = ''
for i in a:
	ans += str(i) + ' '
print(ans.strip())


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
raw_sum = sum(a)
for i in range(1, len(a)):
	a[i] = max(k - a[i - 1], a[i])
print(sum(a) - raw_sum)
for i in a:
	print(i, end=' ')


(x, k) = map(int, input().split())
z = list(map(int, input().split()))
count = 0
for i in range(1, len(z)):
	t = k - z[i] - z[i - 1]
	if t > 0:
		count += t
		z[i] = k - z[i - 1]
print(count)
print(' '.join(map(str, z)))


(_, k) = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d_b = 0
for i in range(1, len(b)):
	need = max(0, k - b[i - 1])
	if need > b[i]:
		d_b += need - b[i]
		b[i] = max(0, k - b[i - 1])
print(d_b)
print(' '.join([str(x) for x in b]))


info = input().split()
days = int(info[0])
walk = int(info[1])
plan = input().split()
count = 0
for i in range(1, days):
	s = int(plan[i - 1]) + int(plan[i])
	if s < walk:
		plan[i] = walk - s + int(plan[i])
		count += walk - s
print(count)
for x in plan:
	print(x, end=' ')


def main():
	from sys import stdin, stdout
	(n, k) = map(int, stdin.readline().split())
	t = tuple(map(int, stdin.readline().split()))
	l = []
	c = 0
	l += [t[0]]
	for i in range(1, n):
		s = l[i - 1] + t[i]
		if s < k:
			c += k - s
			l.append(t[i] + (k - s))
		else:
			l.append(t[i])
	stdout.write(str(c) + '\n')
	for i in l:
		stdout.write(str(i) + ' ')
main()


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


t = 1
for qwe in range(t):
	(n, k) = map(int, input().split())
	listt = list(map(int, input().split()))
	listtans = []
	listtans.append(listt[0])
	ans = 0
	for i in range(1, n):
		temp = k - listtans[i - 1] - listt[i]
		if temp <= 0:
			listtans.append(listt[i])
		else:
			ans += temp
			listtans.append(listt[i] + temp)
	print(ans)
	for i in range(n):
		print(listtans[i], end=' ')
	print()


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


from sys import stdin
(n, k) = list(map(int, stdin.readline().split()))
a = list(map(int, stdin.readline().split()))

def solve(walks: list) -> (int, list):
	new_walks = [0]
	for i in range(1, n):
		s = walks[i] + walks[i - 1] + new_walks[i - 1]
		new_walks.append(max(0, k - s))
	return (sum(new_walks), new_walks)

def print_result(number, walks):
	print(number)
	print(' '.join((str(a[i] + walks[i]) for i in range(n))))
(n1, result1) = solve(a)
(n2, result2) = solve(list(reversed(a)))
if n1 <= n2:
	print_result(n1, result1)
else:
	print_result(n2, result2)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
diff = 0
for i in range(n - 1):
	if sum(a[i:i + 2]) < m:
		diff += m - sum(a[i:i + 2])
		a[i + 1] = m - a[i]
print(diff)
f = ''
for i in a:
	f += str(i) + ' '
print(f)


import random

def main():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	c = 0
	s = str(a[0]) + ' '
	for i in range(1, n):
		if a[i - 1] + a[i] < k:
			c += k - a[i - 1] - a[i]
			a[i] += k - a[i - 1] - a[i]
		s += str(a[i]) + ' '
	print(c)
	print(s)
main()


(k, b) = map(int, input().split())
x = list(map(int, input().split()))
tot = 0
if k == 1:
	print(0)
	print(x[0])
elif k == 2:
	if x[0] + x[1] >= b:
		print(0)
		print(x[0], x[1])
	else:
		print(b - x[0] - x[1])
		print(x[0], b - x[0])
elif k == 3:
	if x[0] + x[1] >= b and x[1] + x[2] >= b:
		print(0)
		print(x[0], x[1], x[2])
	else:
		if x[0] + x[1] < b:
			tot += b - x[1] - x[0]
			x[1] += tot
		if x[1] + x[2] < b:
			tot += b - x[1] - x[2]
			x[2] += b - x[1] - x[2]
		print(tot)
		print(x[0], x[1], x[2])
else:
	for i in range(k - 1):
		if x[i] + x[i + 1] < b:
			tot += b - x[i] - x[i + 1]
			x[i + 1] += b - x[i] - x[i + 1]
	print(tot)
	print(' '.join(map(str, x)))


def best_friend(lst, k):
	result = 0
	for i in range(len(lst)):
		if i + 1 < len(lst) and lst[i] + lst[i + 1] < k:
			result += k - (lst[i] + lst[i + 1])
			lst[i + 1] = k - lst[i]
	return (result, lst)
(N, K) = [int(j) for j in input().split()]
c = [int(x) for x in input().split()]
print(best_friend(c, K)[0])
print(*best_friend(c, K)[1])


(n, k) = map(int, input().split())
abc = list(map(int, input().split()))
dop = 0
for i in range(0, n - 1):
	last_two = abc[i] + abc[i + 1]
	if last_two >= k:
		continue
	else:
		dop += k - last_two
		new_abc = abc[i + 1] + k - last_two
		abc[i + 1] = new_abc
print(dop)
for i in abc:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
min_count = 0
d = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		d = k - a[i] - a[i - 1]
		min_count += d
		a[i] += max(0, d)
print(min_count)
for i in range(n):
	print(a[i], end=' ')


(n, k) = map(int, input().strip().split(' '))
l = list(map(int, input().strip().split(' ')))
extras = 0
beforeSum = sum(l)
for i in range(n - 1):
	if l[i] + l[i + 1] < k:
		l[i + 1] += k - (l[i] + l[i + 1])
		extras += k - (l[i] + l[i + 1])
print(sum(l) - beforeSum)
for i in range(n):
	print(l[i], end=' ')


__author__ = 'Think'
(n, k) = [int(i) for i in input().split()]
days = [int(i) for i in input().split()]
total = 0
for i in range(1, n):
	if days[i] + days[i - 1] >= k:
		continue
	else:
		diff = k - days[i] - days[i - 1]
		total += diff
		days[i] += diff
print(total)
for i in range(n):
	print(days[i], end=' ')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
d = [a[0]]
for i in range(1, n):
	d.append(max(a[i], k - d[i - 1]))
print(sum(d) - sum(a))
print(*d)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = sum(a)
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		a[i] = k - a[i - 1]
print(sum(a) - x)
for i in a:
	print(i, end=' ')


s = input().split(' ')
n = int(s[0])
k = int(s[1])
d = [int(x) for x in input().split(' ')]
over = 0
for i in range(n - 1):
	need = k - d[i + 1]
	if need <= 0:
		continue
	need -= d[i]
	if need > 0:
		d[i + 1] += need
		over += need
print(over)
print(' '.join([str(x) for x in d]))


a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
b = input().split()
out = 0
for i in range(1, len(b)):
	b[i] = b[i]
	if int(b[i]) + int(b[i - 1]) < a[1]:
		out += a[1] - int(b[i]) - int(b[i - 1])
		b[i] = str(a[1] - int(b[i - 1]))
print(out)
print(' '.join(b))


(n, k) = map(int, input().split())
a = [int(z) for z in input().split()]
b = [a[0]]
x = 0
for i in range(n - 1):
	if a[i] <= k:
		b.append(k - a[i])
		if a[i + 1] < b[1 + i]:
			x += b[i + 1] - a[1 + i]
			a[i + 1] = k - a[i]
		else:
			b[i + 1] = a[i + 1]
	else:
		b.append(a[i + 1])
print(x)
print(*b, sep=' ')


[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0, k)
a.append(k)
c = 0
for i in range(2, n + 1):
	if a[i] + a[i - 1] < k:
		m = k - (a[i] + a[i - 1])
		c += m
		a[i] += m
print(c)
print(*a[1:n + 1])


(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
m = 0
s = 0
for i in range(1, n):
	if arr[i] + arr[i - 1] < k:
		s = max(0, k - (arr[i] + arr[i - 1])) + s
		arr[i] = arr[i] + k - arr[i] - arr[i - 1]
print(s)
arr = map(str, arr)
print(' '.join(arr))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, k) = LI()
	a = LI()
	r = 0
	for i in range(1, n):
		t = a[i] + a[i - 1]
		if k <= t:
			continue
		r += k - t
		a[i] += k - t
	return '{}\n{}'.format(r, ' '.join(map(str, a)))
print(main())


def single():
	return input()

def multiple():
	return list(map(int, input().split()))
(n, k) = multiple()
arr = multiple()
t = 0
for i in range(1, n):
	if arr[i] + arr[i - 1] < k:
		temp = k - (arr[i] + arr[i - 1])
		t += temp
		arr[i] += temp
print(t)
for i in arr:
	print(i, end=' ')


(n, v) = list(map(int, input().split()))
l = list(map(int, input().split()))
res = 0
for i in range(len(l) - 1):
	if l[i] + l[i + 1] >= v:
		continue
	else:
		count = v - (l[i] + l[i + 1])
		l[i + 1] += count
		res += count
print(res)
for i in range(len(l)):
	print(l[i], end=' ')


d = list(map(int, input().split()))
k = d[1]
a = list(map(int, input().split()))
s = sum(a)
d = [0 for _ in range(len(a))]
for i in range(1, len(a)):
	if a[i - 1] + a[i] < k:
		a[i] = k - a[i - 1]
s1 = sum(a)
print(s1 - s)
print(' '.join(map(str, a)))


(n, d) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(1, n):
	x = a[i]
	if a[i] + a[i - 1] < d:
		a[i] = d - a[i - 1]
		c += abs(a[i] - x)
print(c)
print(*a, sep=' ')


import math
(n, k) = list(map(int, input().split()))
schedule = list(map(int, input().split()))
count = 0
for ind in range(len(schedule) - 1):
	difference = schedule[ind] + schedule[ind + 1] - k
	if difference < 0:
		count += int(math.fabs(difference))
		schedule[ind + 1] += int(math.fabs(difference))
print(count)
print(' '.join(map(str, schedule)))


(n, k) = map(int, input().split())
lst = {i: int(x) for (i, x) in enumerate(input().split())}
res = 0
for i in range(1, n):
	e = lst[i] + lst[i - 1]
	if e < k:
		res += k - e
		lst[i] += k - e
print(res)
print(*lst.values())


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [i for i in a]
extraCount = 0
for i in range(n - 1):
	theDiff = k - (b[i] + b[i + 1])
	if theDiff > 0:
		extraCount += theDiff
		b[i + 1] += theDiff
print(extraCount)
for x in b:
	print(x, end=' ')


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
(n, k) = get_int()
a = list(get_int())
ans = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		x = k - (a[i] + a[i + 1])
		ans += x
		a[i + 1] += x
print(ans)
for i in range(n):
	print(a[i], end=' ')


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
ans = 0
for i in range(0, n - 1):
	ans += max(0, k - (l[i + 1] + l[i]))
	l[i + 1] += max(0, k - (l[i + 1] + l[i]))
print(ans)
print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = i = 0
for _ in range(n - 1):
	if a[i] + a[i + 1] < k:
		c += k - (a[i] + a[i + 1])
		a[i + 1] += k - (a[i] + a[i + 1])
	i += 1
print(c)
print(' '.join([str(x) for x in a]))


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [0] * len(a)
count = 0
if n == 1:
	if a[0] == k:
		print('0')
		print(k)
	else:
		print('0')
		print(a[0])
else:
	for i in range(1, len(a)):
		if a[i] + a[i - 1] >= k:
			b[i] = a[i]
			b[i - 1] = a[i - 1]
			a[i] = b[i]
			a[i - 1] = b[i - 1]
		elif a[i] + a[i - 1] < k:
			b[i - 1] = a[i - 1]
			b[i] += a[i] + k - (a[i] + a[i - 1])
			count += k - (a[i] + a[i - 1])
			k1 = b[i]
			a[i - 1] = b[i - 1]
			a[i] = k1
	print(count)
	for i in range(len(b)):
		print(b[i], end=' ')


def solve(n, k, a):
	if n == 1:
		r = 0
	else:
		r = 0
		for i in range(1, n):
			if a[i - 1] + a[i] < k:
				c = k - (a[i - 1] + a[i])
				r += c
				a[i] += c
	print(r)
	print(*a)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
solve(n, k, a)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * n
B[0] = A[0]
for i in range(1, n):
	B[i] = max(A[i], k - B[i - 1])
print(sum(B) - sum(A))
print(' '.join(list(map(str, B))))


from sys import stdin
input = stdin.readline
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
total = 0
for i in range(n - 1):
	v = arr[i] + arr[i + 1]
	if v < k:
		arr[i + 1] += k - v
		total += k - v
print(total)
for i in range(n):
	print(arr[i], end=' ')
print()


(d, m) = input().split(' ')
d = int(d)
m = int(m)
x = input().split()
x[0] = int(x[0])
s = 0
for i in range(d - 1):
	if m > int(x[i]) + int(x[i + 1]):
		s += m - (int(x[i]) + int(x[i + 1]))
		x[i + 1] = m - (int(x[i]) + int(x[i + 1])) + int(x[i + 1])
print(s)
for i in x:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(0)
	print(a[0])
else:
	out = 0
	for i in range(1, n):
		out += max(k - a[i - 1] - a[i], 0)
		a[i] = max(k - a[i - 1], a[i])
	print(out)
	print(' '.join(map(str, a)))


import math
first = input()
first = first.split(' ')
n = int(first[0])
k = int(first[1])
second = input()
second = second.split(' ')
list = [int(x) for x in second]
count = 0
i = 0
if n != 1:
	while i < len(list):
		if i + 1 < len(list):
			if list[i] + list[i + 1] < k:
				adding = k - (list[i] + list[i + 1])
				count += adding
				list[i + 1] += adding
		elif list[i] + list[i - 1] < k:
			adding = k - (list[i] + list[i - 1])
			count += adding
			list[i] += adding
		i += 1
	print(count)
	ans_str = ''
	i = 0
	while i < len(list):
		ans_str += str(list[i]) + ' '
		i += 1
	print(ans_str)
else:
	print(0)
	print(list[0])


(n, k) = map(int, input().split())
progulki = list(map(int, input().split()))
count = [0 for i in range(n)]
predok = progulki[0]
count[0] = progulki[0]
count_1 = 0
for i in range(1, n):
	count[i] = progulki[i]
	if k - (progulki[i] + predok) > 0:
		count_1 += k - (progulki[i] + predok)
		count[i] += k - (progulki[i] + predok)
	predok = count[i]
print(count_1)
print(*count)


from sys import stdin
(n, k) = map(int, stdin.readline().rstrip().split(' '))
nums = list(map(int, stdin.readline().rstrip().split(' ')))
t = 0
for i in range(1, len(nums)):
	diff = k - (nums[i] + nums[i - 1])
	if diff > 0:
		t += diff
		nums[i] += diff
print(t)
for num in nums:
	print('{} '.format(num), end='')


(n, k) = map(int, input().split())
l = [*map(int, input().split())]
res = 0
for i in range(1, n):
	d = max(0, k - l[i] - l[i - 1])
	res += d
	l[i] += d
print(res)
print(*l)


def solve(arr, n, w):
	count = 0
	for i in range(1, n):
		if arr[i - 1] + arr[i] < w:
			temp = arr[i]
			arr[i] = w - arr[i - 1]
			count += arr[i] - temp
	return (arr, count)
(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
res = solve(arr, n, w)
print(res[1])
print(*res[0], sep=' ')


(_, k) = map(int, input().split())
A = list(map(int, input().split()))
s = 0
b = k
for (i, a) in enumerate(A):
	c = k - b
	if c > a:
		A[i] = c
		s += c - a
	b = A[i]
print(s)
print(*A)


(n, k) = list(map(int, input().split()))
an = list(map(int, input().split()))
cn = [0] * n
for i in range(1, n):
	cn[i] = max(k - an[i - 1] - cn[i - 1] - an[i], 0)
print(sum(cn))
print(*[cn[i] + an[i] for i in range(n)])


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = 0
for i in range(n - 1):
	sum = a[i] + a[i + 1]
	if sum < k:
		ans += k - sum
		a[i + 1] += k - sum
print(ans)
print(' '.join((str(num) for num in a)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
u = 0
for i in range(1, n):
	m = max(0, k - l[i] - l[i - 1])
	if not m == 0:
		u += m
		l[i] = l[i] + m
print(u)
print(*l)


(n, k) = map(int, input().split())
a = [k] + list(map(int, input().split())) + [k]
ans = 0
for i in range(1, n + 1):
	p = max(k - a[i - 1] - a[i], 0)
	a[i] += p
	ans += p
print(ans)
for i in a[1:-1]:
	print(i, end=' ')


from sys import stdin
(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
ans = 0
for i in range(1, len(arr)):
	b = arr[i]
	a = arr[i - 1]
	if b + a < k:
		cnt = k - b - a
		arr[i] += cnt
		ans += cnt
print(ans)
for i in arr:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(n - 1):
	if i == n - 1:
		if a[i] + a[i + 1] >= k:
			pass
		else:
			s = k - (a[i] + a[i + 1])
			a[i] = a[i] + s
			c = c + s
	elif a[i] + a[i + 1] >= k:
		pass
	else:
		s = k - (a[i] + a[i + 1])
		a[i + 1] = a[i + 1] + s
		c = c + s
print(c)
print(*a)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
s = 0
if n == 1:
	print(0)
	print(a[0])
else:
	for i in range(n - 1):
		if a[i] + a[i + 1] >= k:
			continue
		else:
			s += k - a[i] - a[i + 1]
			a[i + 1] = k - a[i]
	print(s)
	print(*a, sep=' ')


data = list(map(int, input().split(' ')))
n = data[0]
k = data[1]
a = list(map(int, input().split(' ')))
b = [0] * (n + 1)
b[0] = k
i = 0
added = 0
for i in range(n):
	if a[i] + b[i] < k:
		b[i + 1] = k - b[i]
		added += k - (a[i] + b[i])
	else:
		b[i + 1] = a[i]
print(added)
for elem in b[1:]:
	print(elem, end=' ')


(n, k) = list(map(int, input().split()))
line = list(map(int, input().split()))
s = 0
for i in range(len(line) - 1):
	if line[i] + line[i + 1] < k:
		m = k - line[i] - line[i + 1]
		line[i + 1] += k - line[i] - line[i + 1]
		s += m
print(s)
print(' '.join(map(str, line)))


import sys
import math
from collections import defaultdict as ddict
from collections import deque
import heapq
from queue import Queue
fast_inp = lambda : sys.stdin.readline().split('\n')[0]
read_list = lambda : fast_inp().split(' ')
read_listi = lambda : list(map(int, fast_inp().split(' ')))
read_listf = lambda : list(map(float, fast_inp().split(' ')))
read_int = lambda : int(fast_inp())
read_float = lambda : float(fast_inp())
read = lambda : fast_inp()
DEBUG = False

def debug(**kwargs):
	if not DEBUG:
		return
	print('*' * 20)
	for (k, v) in kwargs.items():
		print(f'\t{k}:{v}\t')
	print('*' * 20)

def solve() -> None:
	(n, k) = read_listi()
	arr = read_listi()
	result = 0
	for i in range(1, n):
		if arr[i] + arr[i - 1] < k:
			diff = k - (arr[i] + arr[i - 1])
			arr[i] += diff
			result += diff
	print(result)
	print(*arr)
t = 1
for _ in range(t):
	solve()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
addl_walks = 0
for i in range(1, n):
	shortage = max(0, k - A[i - 1] - A[i])
	(A[i], addl_walks) = (A[i] + shortage, addl_walks + shortage)
print(addl_walks)
print(*A)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
m = s.copy()
j = sum(s)
for i in range(1, n):
	s[i] = max(s[i], k - s[i - 1])
if sum(s) - j > 0:
	print(sum(s) - j)
	print(*s)
else:
	print(0)
	print(*m)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
tot = sum(l)
sum1 = 0
for i in range(len(l) - 1):
	if l[i] + l[i + 1] >= b:
		sum1 += 1
	else:
		l[i + 1] += b - (l[i] + l[i + 1])
if sum1 == len(l) - 1:
	print('0')
	print(*l)
else:
	print(sum(l) - tot)
	print(*l)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
mn = 0
b.append(a[0])
for i in range(1, n):
	b.append(max(a[i], k - b[i - 1]))
	mn += abs(a[i] - b[i])
print(mn)
print(*b)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = 0
for i in range(1, n):
	if arr[i] + arr[i - 1] >= k:
		pass
	else:
		t = k - arr[i - 1]
		ans += t - arr[i]
		arr[i] = t
print(ans)
print(*arr)


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
h = 0
for i in range(1, n):
	t = k - s[i] - s[i - 1]
	s[i - 1] = str(s[i - 1])
	if t > 0:
		s[i] += t
		h += t
s[n - 1] = str(s[n - 1])
print(h)
print(' '.join(s))


(n, k) = input().split(' ')
n = int(n)
k = int(k)
s = input()
p1 = 0
p2 = 0
li = s.split(' ')
for i in range(n):
	li[i] = int(li[i])
	p1 += li[i]
for i in range(n - 1):
	if li[i] + li[i + 1] < k:
		p2 += k - li[i] - li[i + 1]
		li[i + 1] += k - li[i] - li[i + 1]
print(p2)
for i in range(n):
	print(str(li[i]), end=' ')


(a, total) = map(int, input().split(' '))
walk = list(map(int, input().split(' ')))
answer = 0
i = 0
flag = True
if len(walk) == 1:
	answer = 0
else:
	while i + 1 < len(walk):
		if walk[i] + walk[i + 1] < total:
			answer += total - (walk[i] + walk[i + 1])
			walk[i + 1] += total - (walk[i] + walk[i + 1])
			i += 1
		else:
			i += 1
print(answer)
for i in walk:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
s = 0
s1 = 0
a = arr[:]
for i in range(1, n):
	if a[i] < k - a[i - 1]:
		s += k - a[i - 1] - a[i]
		a[i] = k - a[i - 1]
arr.reverse()
for i in range(1, n):
	if arr[i] < k - arr[i - 1]:
		s1 += k - arr[i - 1] - arr[i]
		arr[i] = k - arr[i - 1]
if s1 >= s:
	print(s)
	print(*a)
else:
	print(s1)
	print(*arr)


(days, k) = map(int, input().split(' '))
shed = [int(x) for x in input().split(' ')]
tot = 0
for i in range(days - 1):
	if shed[i] + shed[i + 1] < k:
		toty = k - shed[i + 1] - shed[i]
		shed[i + 1] = shed[i + 1] + toty
		tot += toty
print(tot)
print(*shed, sep=' ')


(n, k) = map(int, input().split())
days = list(map(int, input().split()))
w = 0
for i in range(n - 1):
	if days[i] + days[i + 1] < k:
		w = w + (k - days[i] - days[i + 1])
		days[i + 1] = k - days[i]
print(w)
print(' '.join(map(str, days)))


b = list(map(int, input().split()))
a = list(map(int, input().split()))
c = []
s = 0
for i in range(0, b[0]):
	if i == 0:
		p = a[i]
		c.append(a[i])
	else:
		l = b[1] - p
		if a[i] <= l:
			c.append(l)
			p = l
		else:
			c.append(a[i])
			p = a[i]
print(sum(c) - sum(a))
for i in range(0, b[0]):
	print(c[i], end=' ')


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
(w, e) = (0, 0)
for i in range(1, a):
	w = z[i] + z[i - 1]
	if w < b:
		e += b - w
		z[i] = b - z[i - 1]
print(e)
print(*z)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
l = zzz()
ans = 0
for i in range(1, n):
	p = l[i]
	x = l[i - 1]
	t = m - (p + x)
	if t >= 1:
		ans += t
		l[i] = p + t
print(ans)
print(*l)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split(' ')]
ans = 0
for i in range(1, len(arr)):
	sum = arr[i] + arr[i - 1]
	if sum < k:
		arr[i] += k - sum
		ans += k - sum
print(ans)
for i in arr:
	print(str(i) + ' ', end='')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
all = 0
for i in range(1, n):
	add = max(0, k - (a[i] + a[i - 1]))
	all += add
	a[i] += add
print(all)
print(*a)


(n, k) = map(int, input().split())
(*l,) = map(int, input().split())
(x, d) = (sum(l), 0)
for (i, a) in enumerate(l):
	if a < d:
		l[i] = a = d
	d = k - a
print(sum(l) - x)
print(*l)


I = lambda : map(int, input().split())
(n, k) = I()
b = list(I())
r = 0
for i in range(1, n):
	t = k - b[i] - b[i - 1]
	if t > 0:
		b[i] += t
		r += t
print(str(r) + '\n' + ' '.join(map(str, b)))


(n, k) = map(int, input().split())
(*l,) = map(int, input().split())
m = 0
for i in range(1, n):
	f = l[i - 1] + l[i]
	if f < k:
		m += k - f
		l[i] += k - f
print(m)
print(*l)


from sys import stdin
(nbJours, jourConsecutif) = map(int, stdin.readline().split())
planning = list(map(int, stdin.readline().split()))
supplement = 0
for i in range(1, nbJours):
	diff = jourConsecutif - (planning[i - 1] + planning[i])
	maximum = max(0, diff)
	supplement += maximum
	planning[i] += maximum
print(supplement)
print(*planning)


ans = 0
(N, K) = map(int, input().split())
x = list(map(int, input().split()))
for (i, n) in enumerate(x[1:]):
	if n + x[i] < K:
		x[i + 1] += K - n - x[i]
		ans += K - n - x[i]
print(ans)
for (i, n) in enumerate(x[:N - 1]):
	print(n, end=' ')
print(x[-1])


import sys
global bb, aa
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
rez = sum(A)
B = []
for i in range(n - 1):
	if A[i] + A[i + 1] < k:
		A[i + 1] += k - A[i] - A[i + 1]
rez -= sum(A)
print(abs(rez))
print(*A)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
mim = sum(c)
for i in range(a - 1):
	if c[i] + c[i + 1] < b:
		c[i + 1] += b - (c[i] + c[i + 1])
print(sum(c) - mim)
print(*c)


def find_ans(a, k):
	n = len(a)
	if n == 1:
		return (a, 0)
	res = 0
	for i in range(1, n):
		dif = k - a[i] - a[i - 1]
		if dif > 0:
			a[i] += dif
			res += dif
	return (a, res)
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
(a, res) = find_ans(a, k)
print(res)
for i in range(n):
	if i != 0:
		print(' ', end='')
	print(a[i], end='')


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
(n, k) = inp()
a = inp()
ans = float('inf')
prev = k
res = 0
for i in range(n):
	temp = k - prev - a[i]
	if temp > 0:
		a[i] += temp
		res += temp
	prev = a[i]
print(res)
print(*a)


def DogWalk(n, k, days):
	extra = 0
	for i in range(1, n):
		if days[i] + days[i - 1] < k:
			extra += k - (days[i] + days[i - 1])
			days[i] += k - (days[i] + days[i - 1])
	print(extra)
	for i in days:
		print(i, end=' ')
(n, k) = map(int, input().split())
days = list(map(int, input().split()))
DogWalk(n, k, days)


(n, k) = map(int, input().split())
arrays = list(map(int, input().split()))
s = 0
if n > 1:
	for i in range(1, n):
		if arrays[i] + arrays[i - 1] < k:
			diff = k - arrays[i] - arrays[i - 1]
			arrays[i] += diff
			s += diff
print(s)
print(*arrays)


(n, k) = map(int, input().split(' '))
list1 = list(map(int, input().split(' ')))
list2 = list1.copy()
change = 0
for i in range(1, n):
	list1[i] = max(k - list1[i - 1], list1[i])
	change += list1[i] - list2[i]
print(change)
for (i, val) in enumerate(list1):
	print(val, end=' ')


n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
for i in range(1, n[0]):
	if a[i] + a[i - 1] < n[1]:
		count += n[1] - (a[i] + a[i - 1])
		a[i] += n[1] - (a[i] + a[i - 1])
print(count)
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split())
listNum = list(map(int, input().split()))
adder = 0
for i in range(1, n):
	change = max(0, k - listNum[i] - listNum[i - 1])
	listNum[i] += change
	adder += change
print(adder)
for i in listNum[:-1]:
	print(i, end=' ')
print(listNum[-1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cn = 0
for i in range(1, n):
	if a[i - 1] + a[i] < k:
		t = k - a[i] - a[i - 1]
		cn += t
		a[i] += t
print(cn)
print(*a)


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
cin = stdin.readline

def cout(x):
	stdout.write(str(x) + '\n')

def nexint():
	return int(stdin.readline())

def readline():
	return map(int, stdin.readline().split())

def readlist(type=int):
	return list(map(type, stdin.readline().split()))

def sorted_indexes(arr):
	return sorted(range(len(arr)), key=arr.__getitem__)

def printr(arr):
	[stdout.write(str(x) + ' ') for x in arr]
	cout('')

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError

def dist(x, y):
	return math.sqrt(x * x + y * y)
(n, k) = readline()
a = readlist(int)
ans = 0
for i in range(1, n):
	s = a[i - 1] + a[i]
	if k > s:
		a[i] += k - s
		ans += k - s
cout(ans)
printr(a)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
diff = 0
b = [a[0]]
for i in range(1, n):
	b.append(max(a[i], k - b[i - 1]))
	diff += b[i] - a[i]
print(diff)
print(*b)


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
sum = 0
for i in range(1, n):
	sum += max(0, k - A[i] - A[i - 1])
	A[i] += max(0, k - A[i] - A[i - 1])
ans = ''
for i in A:
	ans += str(i) + ' '
print(str(sum) + '\n' + ans)


inp = lambda : map(int, input().rstrip().split())
(n, k) = inp()
a = list(inp())
b = [a[0]]
for i in range(1, n):
	x = max(a[i], k - b[-1])
	b.append(x)
print(sum(b) - sum(a))
print(*b)


(n, k) = map(int, input().split())
line = list(map(int, input().split()))
count = 0
for i in range(n - 1):
	if line[i] + line[i + 1] < k:
		m = k - line[i] - line[i + 1]
		line[i + 1] += m
		count += m
print(count)
print(*line)


man = list(map(int, input().rstrip().split()))
ca = list(map(int, input().rstrip().split()))
k = man[1]
s = man[0]
sum = 0
b = []
f = 0
b.append(ca[0])
for i in range(1, s):
	x = ca[i - 1] + ca[i]
	if f == 0 and x < k:
		ca[i] += k - x
		sum += k - x
	b.append(ca[i])
print(sum)
for i in b:
	print(i, end=' ')


(m, n) = input().split()
m = int(m)
n = int(n)
l = list(map(int, input().split()))
k = n - l[0]
p = []
ans = 0
for i in range(1, m):
	if k > l[i]:
		ans += k - l[i]
		l[i] += k - l[i]
	k = n - l[i]
print(ans)
for x in l:
	print(x, end=' ')
print()


(m, n) = map(int, input().split())
t = list(map(int, input().split()))
t.append(n + 2)
d = 0
b = t[1] + t[0]
for i in range(1, m):
	if b >= n and t[i] + t[i + 1] < n:
		d += n - (t[i] + t[i + 1])
		t[i + 1] += n - (t[i] + t[i + 1])
	if b < n and t[i] + t[i + 1] >= n:
		d += n - (t[i] + t[i - 1])
		t[i] += n - (t[i] + t[i - 1])
	if b < n and t[i] + t[i + 1] < n:
		d += n - (t[i] + t[i - 1])
		t[i] += n - (t[i] + t[i - 1])
	b = t[i] + t[i + 1]
print(d)
for i in range(m):
	print(t[i], end=' ')


(num, min_days) = input().split()
plan = [int(x) for x in input().split()]
(num, min_days) = (int(num), int(min_days))
count = 0
pred = plan[0]
for i in range(1, len(plan)):
	if plan[i] + pred < min_days:
		count += min_days - (plan[i] + pred)
		plan[i] += min_days - (plan[i] + pred)
	pred = plan[i]
print(count)
for i in plan:
	print(i, end=' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
r = sum(c)
d = ''
for i in range(1, a):
	if c[i] + c[i - 1] < b:
		c[i] = c[i] + (b - (c[i] + c[i - 1]))
p = sum(c) - r
for i in c:
	d += str(i) + ' '
print(p)
print(d)


(n, k) = map(int, input().split())
ch = input()
l = ch.split()
s = 0
for i in range(1, n):
	if k >= int(l[i]) + int(l[i - 1]):
		s += k - int(l[i]) - int(l[i - 1])
		l[i] = str(int(l[i]) + k - int(l[i]) - int(l[i - 1]))
print(s)
for i in range(n):
	print(l[i], end=' ')


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, k) = get_ints()
	arr = get_list()
	prev = sum(arr)
	for i in range(n - 1):
		curr = arr[i]
		next = arr[i + 1]
		if curr + next < k:
			diff = k - (curr + next)
			arr[i + 1] += diff
	print(sum(arr) - prev)
	print(*arr)


import math
import sys
n = sys.stdin.readline().split()
n = [int(i) for i in n]
walks = n[0]
days = n[1]
a = sys.stdin.readline().split()
a = [int(i) for i in a]
extra = 0
for i in range(1, len(a)):
	s = a[i] + a[i - 1]
	if s < days:
		a[i] += days - s
		extra += days - s
print(extra)
print(*a, sep=' ')


(n, k) = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
ret = 0
for i in range(1, n):
	box = max(k - data[i - 1] - data[i], 0)
	data[i] += box
	ret += box
print(ret)
for i in data:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for i in range(1, n):
	t = max(k - a[i - 1], a[i])
	s += t - a[i]
	a[i] = t
print(s)
print(*a)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
for i in range(1, len(arr)):
	if arr[i] + arr[i - 1] >= k:
		continue
	else:
		count += k - (arr[i - 1] + arr[i])
		arr[i] += k - (arr[i - 1] + arr[i])
print(count)
for i in arr:
	print(i, end=' ')
print(' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
i = 1
while i < n:
	a[i] = max(a[i], k - a[i - 1])
	i += 1
print(sum(a) - s)
print(*a)


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
s0 = sum(data)
for i in range(n - 1):
	if data[i] + data[i + 1] < k:
		data[i + 1] = k - data[i]
print(sum(data) - s0)
print(' '.join(map(str, data)))


import sys, threading, os.path
import string
import collections, heapq, math, bisect
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	(n, m) = list(map(int, input.readline().split()))
	lis = list(map(int, input.readline().split()))
	count = 0
	for i in range(1, n):
		if lis[i] + lis[i - 1] < m:
			add = m - (lis[i] + lis[i - 1])
			lis[i] += add
			count += add
	output = str(count) + '\n' + ' '.join(map(str, lis))
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
a = int(0)
for i in range(1, x, 1):
	if l[i - 1] + l[i] < y:
		a += -l[i - 1] - l[i] + y
		l[i] = y - l[i - 1]
print(a)
print(*l)


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

def diff(l):
	l = l[:]
	for i in range(1, n):
		l[i] += max(0, k - l[i] - l[i - 1])
	return l
b = diff(a)
d = sum(b) - sum(a)
print(d)
print(' '.join(map(str, b)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ant = k
total = 0
for i in range(len(a)):
	c = a[i] + ant
	if c < k:
		a[i] += k - c
		total += k - c
	ant = a[i]
print(total)
for num in a:
	print(num, end=' ')
print()


(n, k) = map(int, input().split())
d = [0] * n
l = [int(j) for j in input().split()]
d[0] = l[0]
y = 0
for i in range(1, n):
	t = max(k - (l[i] + d[i - 1]), 0)
	d[i] = l[i] + t
	y += t
print(y)
print(*d)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
b = a[:]
for i in range(1, n):
	b[i] = max(b[i], k - b[i - 1])
ans = sum((b[i] - a[i] for i in range(n)))
print(ans)
print(*b)


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = input()
A = []
x = 0
for i in a.split():
	A.append(int(i))
if n == 1:
	print(0)
	print(A[0])
else:
	if A[0] + A[1] < k:
		x = k - A[0] - A[1]
		A[1] = k - A[0]
	for j in range(1, n - 1):
		if A[j] + A[j + 1] >= k:
			continue
		else:
			x = x + k - A[j] - A[j + 1]
			A[j + 1] = k - A[j]
	if A[-2] + A[-1] < k:
		x = x + k - A[-2] - A[-1]
		A[-1] = 5 - A[-2]
	print(x)
	s = ''
	for l in A:
		s = s + str(l) + ' '
	print(s)


(n, k) = map(int, input().split())
ch = input()
L = list(map(int, ch.split()))
c = 0
for i in range(n - 1):
	if L[i] + L[i + 1] < k:
		c = c + k - (L[i] + L[i + 1])
		L[i + 1] += k - (L[i] + L[i + 1])
print(c)
for i in L:
	print(i, end=' ')


(n, k) = map(int, input().strip().split())
a = [int(v) for v in input().strip().split()]
ans = 0
for i in range(1, n):
	temp = max(0, k - a[i] - a[i - 1])
	a[i] = temp + a[i]
	ans += temp
print(ans)
print(' '.join(map(str, a)))


(sizeofara, walknumber) = map(int, input().split())
ara = list(map(int, input().split()))
count = 0
for i in range(0, sizeofara - 1):
	x = ara[i] + ara[i + 1]
	if x < walknumber:
		count += walknumber - x
		ara[i + 1] += walknumber - x
print(count)
print(*ara)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
for i in range(len(a) - 1):
	if a[i] + a[i + 1] >= k:
		continue
	else:
		a[i + 1] = k - a[i]
print(sum(a) - s)
print(*a, sep=' ')


nn = list(map(int, input().rstrip().split()))
n = nn[0]
k = nn[1]
ht = list(map(int, input().rstrip().split()))
addn = 0
for i in range(n - 1):
	if ht[i] + ht[i + 1] < k:
		addn += k - ht[i] - ht[i + 1]
		ht[i + 1] = k - ht[i]
print(addn)
ht = [str(a) for a in ht]
print(' '.join(ht))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
b = arr.copy()
diff = 0
for i in range(0, n - 1):
	if b[i] + b[i + 1] < k:
		diff += k - (b[i] + b[i + 1])
		b[i + 1] += k - (b[i] + b[i + 1])
print(diff)
for i in range(n):
	print(b[i], end=' ')
print('')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sm = sum(a)
for i in range(1, len(a)):
	if a[i] + a[i - 1] < k:
		a[i] = k - a[i - 1]
print(sum(a) - sm)
print(*a)


(days, min_walks) = map(int, input().split())
walks = list(map(int, input().split()))
news_walks = 0
for i in range(1, days):
	j = walks[i]
	if j + walks[i - 1] < min_walks:
		walks[i] = min_walks - walks[i - 1]
		news_walks += walks[i] - j
print(news_walks)
print(' '.join(map(str, walks)))


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
count = 0
for i in range(len(arr) - 1):
	count += max(0, k - arr[i] - arr[i + 1])
	arr[i + 1] += max(0, k - arr[i] - arr[i + 1])
print(count)
print(' '.join([str(x) for x in arr]))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
(n, k) = sp()
A = l()
dp = [0 for i in range(n)]
for i in range(1, n):
	dp[i] = max(k - A[i] - A[i - 1], 0)
	A[i] += dp[i]
print(sum(dp))
print(*A)


s = input()
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
s = input()
b = s.split()
for i in range(len(b)):
	b[i] = int(b[i])
sum = 0
i = 1
while i < len(b):
	if b[i] + b[i - 1] < a[1]:
		sum += a[1] - b[i] - b[i - 1]
		b[i] = a[1] - b[i - 1]
	i += 1
print(sum)
for i in range(len(b)):
	print(b[i], end=' ')


def get_ans():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	for idx in range(len(l) - 1):
		if l[idx] + l[idx + 1] < k:
			diff = k - (l[idx] + l[idx + 1])
			l[idx + 1] += diff
			ans += diff
	print(ans)
	print(' '.join((str(x) for x in l)))
get_ans()


(n, k) = map(int, input().split())
a = [k] + [int(x) for x in input().split()]
pre = sum(a)
for i in range(1, n + 1):
	if a[i] + a[i - 1] >= k:
		pass
	else:
		a[i] = k - a[i - 1]
print(sum(a) - pre)
del a[0]
print(' '.join([str(x) for x in a]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
prev = k
total = 0
b = [0] * n
for (i, j) in enumerate(a):
	missing = k - prev - a[i]
	if missing > 0:
		total += missing
		b[i] = a[i] + missing
		prev = b[i]
	else:
		b[i] = a[i]
		prev = a[i]
print(total)
print(' '.join((str(x) for x in b)))


def main():
	nm = list(map(int, input().split()))
	n = nm[0]
	k = nm[1]
	a = list(map(int, input().split()))
	additionalWalks = 0
	for i in range(n - 1):
		if a[i] + a[i + 1] < k:
			additionalWalks += k - (a[i] + a[i + 1])
			a[i + 1] += k - (a[i] + a[i + 1])
	print(additionalWalks)
	for i in a:
		print(i, end=' ')
main()


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
s = [m[i] + m[i + 1] for i in range(n - 1)] + [0]
ans = 0
for i in range(n - 1):
	while s[i] < k:
		s[i] += 1
		s[i + 1] += 1
		m[i + 1] += 1
		ans += 1
print(ans)
print(*m)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = list(a)
for i in range(1, n):
	b[i] += k - b[i - 1] - a[i]
	if b[i] < 0:
		b[i] = 0
	if b[i] < a[i]:
		b[i] = a[i]
print(sum([b[i] - a[i] for i in range(n)]))
print(*[x for x in b])


def func():
	l.insert(0, k)
	l.append(k)
	n = len(l)
	c = 0
	s = sum(l[:2])
	if s < k:
		l[1] += k - s
		c += k - s
	for i in range(1, n - 1):
		s = l[i] + l[i + 1]
		if s < k:
			c += k - s
			l[i + 1] += k - s
	print(c)
	print(*l[1:n - 1])
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
func()


(n, k) = map(int, input().split())
w = [int(y) for y in input().split()]
total = 0
for x in range(n - 1):
	if sum(w[x:x + 2]) < k:
		change = k - sum(w[x:x + 2])
		total += change
		w[x + 1] += change
print(total)
print(' '.join((str(x) for x in w)))


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
u = 0
for i in range(n - 1):
	p = t[i] + t[i + 1]
	if p < k:
		t[i + 1] += k - p
		u += k - p
	else:
		pass
print(u)
print(*t)


(n, k) = [int(x) for x in input().split()]
data = [k]
data.extend([int(x) for x in input().split()])
additional_walk = 0
for x in range(1, len(data)):
	dif = k - (data[x] + data[x - 1])
	if dif > 0:
		additional_walk += dif
		data[x] += dif
	else:
		continue
print(additional_walk)
for x in data[1:]:
	print(x, end=' ')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
b = [a[0]]
for i in range(n - 1):
	t = a[i] + a[i + 1]
	if t < k:
		r = k - t
		count += r
		a[i + 1] += r
	b.append(a[i + 1])
print(count)
print(*b)


import bisect
line = input()
words = []
for word in line.split():
	words.append(word)
n = int(words[0])
k = int(words[1])
line = input()
v = []
for word in line.split():
	v.append(int(word))
answer = 0
for i in range(1, n):
	if v[i] + v[i - 1] < k:
		needed = k - (v[i] + v[i - 1])
		answer += needed
		v[i] += needed
print(answer)
for number in v:
	print(number, sep=' ', end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[0]]
m = 0
for i in range(1, len(a)):
	if a[i - 1] + a[i] < k:
		m += k - a[i - 1] - a[i]
		a[i] += k - a[i - 1] - a[i]
	b.append(a[i])
print(m)
print(*b)


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
c = 0
for i in range(1, n):
	if ls[i] + ls[i - 1] < k:
		d = k - (ls[i] + ls[i - 1])
		c = c + d
		ls[i] = ls[i] + d
print(c)
s = ''
for i in range(n):
	if i == n - 1:
		s = s + str(ls[i])
	else:
		s = s + str(ls[i]) + ' '
print(s)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
res = 0
for i in range(1, len(arr)):
	if arr[i - 1] + arr[i] < k:
		diff = k - (arr[i - 1] + arr[i])
		arr[i] += diff
		res += diff
print(res)
print(' '.join(map(str, arr)))


s = [int(i) for i in input().split()]
(n, k) = (s[0], s[1])
a = [int(i) for i in input().split()]
b = [0] * n
(b[0], b[-1]) = (0, 0)
for i in range(1, n):
	s = b[i - 1] + a[i - 1] + a[i] - k
	if s > 0:
		b[i] = 0
	else:
		b[i] = -s
for i in range(n):
	b[i] += a[i]
print(sum(b) - sum(a))
for i in range(n):
	print(b[i], end=' ')


(n, k) = [int(i) for i in input().split()]
walks = [int(i) for i in input().split()]
extra = 0
for i in range(1, n):
	tot = walks[i] + walks[i - 1]
	if tot < k:
		dif = k - tot
		walks[i] += dif
		extra += dif
res = str(extra) + '\n'
for e in map(str, walks):
	res += e + ' '
print(res)


(n, i) = map(int, input().split())
L = list(map(int, input().split()))
minimo = 0
for k in range(1, n):
	falta = i - L[k] - L[k - 1]
	if falta > 0:
		L[k] += falta
		minimo += falta
print(minimo)
print(' '.join(map(str, L)))


from sys import stdin
(n, k) = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
ans = 0
for i in range(n - 1):
	temp_s = k - (arr[i] + arr[i + 1])
	if temp_s > 0:
		arr[i + 1] += temp_s
		ans += temp_s
print(ans)
for i in arr:
	print(i, end=' ')
print()


(n, k) = list(map(int, input().split()))
days = list(map(int, input().split()))
overoll_cost = 0
for day_index in range(1, n):
	walked_num = days[day_index] + days[day_index - 1]
	if walked_num < k:
		overoll_cost += k - walked_num
		days[day_index] += k - walked_num
print(overoll_cost)
print(' '.join(map(str, days)))


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
prev = sum(arr)
for i in range(n - 1):
	if arr[i] + arr[i + 1] < k:
		arr[i + 1] += k - arr[i + 1] - arr[i]
diff = sum(arr) - prev
print(diff, ' '.join(map(str, arr)), sep='\n')


import sys

def input():
	return sys.stdin.readline()[:-1]
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = 0
for i in range(1, n):
	s = a[i - 1] + a[i]
	if s >= k:
		continue
	else:
		ans += k - s
		a[i] += k - s
print(ans)
print(' '.join((str(x) for x in a)))


(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
C = 0
for i in range(0, n - 1):
	if A[i] + A[i + 1] < k:
		C += k - A[i + 1] - A[i]
		A[i + 1] = A[i + 1] - A[i] + k - A[i + 1]
print(C)
for i in range(n):
	print(A[i], end=' ')


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


a1 = [int(s) for s in input().split()]
a2 = [int(s) for s in input().split()]
k = a1[1]
array = [k] + a2
extraWalks = 0
for i in range(1, len(array)):
	walks = array[i - 1] + array[i]
	if walks < k:
		extra = k - walks
		array[i] += extra
		extraWalks += extra
print(extraWalks)
out = ''
for i in range(1, len(array)):
	out = out + str(array[i])
	if i < len(array) - 1:
		out = out + ' '
print(out)


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


from sys import stdin as si
from collections import Counter as c

class Solution:

	def bazinga(self, a, b, c):
		r = 0
		if a == 0:
			r = b
			c = [b]
		elif a == 1:
			return (r, c)
		else:
			for i in range(1, a):
				z = max(0, b - c[i] - c[i - 1])
				r += z
				c[i] += z
		return (r, c)
(n, m) = map(int, si.readline().strip().split())
x = list(map(int, si.readline().strip().split()))
S = Solution()
ans = S.bazinga(n, m, x)
print(ans[0])
print(str(ans[1]).replace('[', '').replace(']', '').replace(',', ''))


(l, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
for i in range(1, l):
	if a[i - 1] + a[i] < k:
		c = k - a[i - 1]
		count += c - a[i]
		a[i] = c
print(count)
print(*a)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def divi(n):
	cnt = 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i == n // i:
				cnt += 1
			else:
				cnt += 2
	return cnt

def main():
	(n, k) = mi()
	arr = li()
	if n == 1:
		print(0)
		print(arr[0])
	else:
		cnt = 0
		for i in range(1, n):
			if arr[i] + arr[i - 1] < k:
				cnt += k - arr[i - 1] - arr[i]
				arr[i] = k - arr[i - 1]
		print(cnt)
		print(*arr)
main()


(n, m) = map(int, input().split())
our = list(map(int, input().split()))
res = 0
for i in range(1, len(our)):
	if our[i - 1] + our[i] < m:
		res += m - our[i] - our[i - 1]
		our[i] += m - our[i] - our[i - 1]
print(res)
print(' '.join(map(str, our)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = 0
for i in range(n - 1):
	if l[i] + l[i + 1] >= k:
		continue
	else:
		t = l[i + 1]
		l[i + 1] = k - l[i]
		m = m + l[i + 1] - t
print(m)
print(*l)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
i = 0
x = 0
while i < len(arr):
	if i + 1 < len(arr):
		if arr[i] + arr[i + 1] < k:
			x += k - (arr[i + 1] + arr[i])
			arr[i + 1] = arr[i + 1] + k - (arr[i + 1] + arr[i])
	else:
		break
	i += 1
print(x)
ans = ''
for y in range(0, len(arr)):
	ans += str(arr[y]) + ' '
print(ans)


(n, k) = map(int, input().split())
z = list(map(int, input().split()))
s = sum(z)
for i in range(1, n):
	if z[i] + z[i - 1] < k:
		z[i] += k - (z[i] + z[i - 1])
print(sum(z) - s)
print(*z)


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
t2 = []
for i in range(n):
	t2.append(t[i])
s = 0
for i in range(n - 1):
	if t[i] + t[i + 1] < k:
		t[i + 1] = k - t[i]
for i in range(n):
	s += t[i] - t2[i]
t = list(map(str, t))
print(s)
print(' '.join(t))


(n, k) = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]
ans = 0
res = ''
prev = k
for x in arr:
	if x + prev < k:
		ans += k - (x + prev)
		x += k - (x + prev)
	res += str(x) + ' '
	prev = x
print(ans)
print(res)


from sys import stdin, stdout
I = lambda : map(int, stdin.readline().rstrip().split())
(n, k) = I()
b = list(I())
a = 0
for i in range(1, n):
	temp0 = k - (b[i - 1] + b[i])
	if temp0 > 0:
		b[i] = b[i] + temp0
		a = a + temp0
stdout.write(str(a) + '\n' + ' '.join(map(str, b)))


import sys, math, random
(n, k) = list(map(int, input().split()))
z = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	if z[i] + z[i + 1] < k:
		ans += k - z[i + 1] - z[i]
		z[i + 1] += k - z[i + 1] - z[i]
print(ans)
print(*z)


(n, d) = map(int, input().split())
dp = list(map(int, input().split()))
res = 0
for i in range(1, len(dp)):
	if dp[i] + dp[i - 1] < d:
		res += d - (dp[i] + dp[i - 1])
		dp[i] = d - dp[i - 1]
print(res)
for i in range(0, len(dp)):
	print(dp[i], end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = ['0' for i in range(n)]
k = 0
for i in range(1, n):
	if l[i] + l[i - 1] >= m:
		l1[i] = str(l[i])
		l1[i - 1] = str(l[i - 1])
	elif l[i] + l[i - 1] < m:
		k = k + m - l[i] - l[i - 1]
		l[i] = m - l[i - 1]
		l1[i] = str(l[i])
		l1[i - 1] = str(l[i - 1])
if n != 1:
	print(k)
	print(' '.join(l1))
else:
	print(0)
	print(l[0])


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
	print(l)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans
(n, k) = mi()
l = li()
count = 0
for i in range(1, n):
	if l[i] + l[i - 1] < k:
		count += k - l[i - 1] - l[i]
		l[i] = k - l[i - 1]
print(count)
print(' '.join(map(str, l)))


def do():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	totalNeed = 0
	while 1:
		if i + 1 >= n:
			break
		curSum = a[i] + a[i + 1]
		need = k - curSum
		totalNeed += max(0, need)
		if need > 0:
			a[i + 1] += need
		i += 1
	print(totalNeed)
	return a
rs = do()
tobeprinted = ''
for r in rs:
	tobeprinted += str(r) + ' '
print(tobeprinted[:-1])


(n, k) = map(int, input().split())
days = list(map(int, input().split()))
sum1 = sum(days)
for i in range(0, n - 1):
	(x1, x2) = (days[i], days[i + 1])
	days[i + 1] += max(k - (x1 + x2), 0)
print(sum(days) - sum1)
print(*days)


(n, k) = map(int, input().split(' '))
s = list(map(int, input().split(' ')))
d = 0
counter = 0
for i in range(len(s) - 1):
	if s[i] + s[i + 1] < k:
		t = s[i] + s[i + 1]
		d = k - t
		counter += d
		s[i + 1] = s[i + 1] + d
print(counter)
for i in range(len(s)):
	print(s[i], end=' ')


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
t = 0
for i in range(n - 1):
	a1 = nums[i]
	a2 = nums[i + 1]
	if a1 + a2 < k:
		t += k - (a1 + a2)
		nums[i + 1] = k - a1
	else:
		pass
print(t)
print(' '.join(map(str, nums)))


import copy
(n, k) = map(int, input().split())
l = input()
l = [int(i) for i in l.split()]
z = copy.deepcopy(l)
for i in range(len(l) - 1):
	if l[i] + l[i + 1] < k:
		l[i + 1] += k - (l[i] + l[i + 1])
print(sum(l) - sum(z))
for i in l:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = input().split()
walk = 0
for i in range(1, n):
	x = int(arr[i]) + int(arr[i - 1])
	if x < k:
		walk += k - x
		arr[i] = int(arr[i]) + k - x
print(walk)
print(*arr)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [a[i] + a[i + 1] for i in range(len(a) - 1)]
ans = 0
for i in range(len(b)):
	to_add = k - b[i]
	if to_add > 0:
		ans += to_add
		b[i] += to_add
		if i != len(b) - 1:
			b[i + 1] += to_add
		a[i + 1] += to_add
print(ans)
print(' '.join([str(i) for i in a]))


(number_of_days, minimum_number_of_walks) = map(int, input().split(' '))
planned = []
inputs = list(map(int, input().split(' ')))
for i in range(number_of_days):
	planned.append(int(inputs[i]))
additional = 0
for i in range(number_of_days):
	if number_of_days == 1:
		break
	if i == number_of_days - 1:
		if planned[i] + planned[i - 1] < minimum_number_of_walks:
			add = minimum_number_of_walks - (planned[i] + planned[i - 1])
			planned[i - 1] += add
			additional += add
	elif planned[i] + planned[i + 1] < minimum_number_of_walks:
		add = minimum_number_of_walks - (planned[i] + planned[i + 1])
		planned[i + 1] += add
		additional += add
print(additional)
output = ''
for (index, value) in enumerate(planned):
	output += str(value)
	if index != len(planned) - 1:
		output += ' '
print(output)


def helppolycarp(days, a, k, i=0, mcount=0):
	if i + 1 == days:
		a.append(mcount)
		return a
	if a[i + 1] + a[i] < k:
		mcount = abs(a[i + 1] + a[i] - k) + mcount
		a[i + 1] = abs(a[i + 1] + a[i] - k) + a[i + 1]
		return helppolycarp(days, a, k, i + 1, mcount)
	else:
		return helppolycarp(days, a, k, i + 1, mcount)
(days, k) = input().split()
days = int(days)
k = int(k)
a = list(map(int, input().split()))
ans = helppolycarp(days, a, k)
print(ans[len(ans) - 1])
ans.pop()
for i in range(0, len(ans)):
	print(ans[i], end=' ')


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
res = 0
for i in range(n - 1):
	if ls[i] + ls[i + 1] < k:
		val = k - (ls[i] + ls[i + 1])
		res += val
		ls[i + 1] += val
print(res)
print(*ls)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [None] * n
b[0] = a[0]
ans = 0
for i in range(1, n):
	cnt = max(a[i], k - b[i - 1])
	ans += cnt - a[i]
	b[i] = cnt
print(ans)
print(*b)


I = lambda : list(map(int, input().split()))
(n, k) = I()
a = I()
b = [i for i in a]
c = [i for i in a]
(ans1, ans2) = (0, 0)
for i in range(1, n):
	additional_walk = max(k - b[i] - b[i - 1], 0)
	b[i] += additional_walk
	ans1 += additional_walk
ans2 += max(k - c[0], 0)
c[0] += max(k - c[0], 0)
for i in range(1, n):
	additional_walk = max(k - c[i] - c[i - 1], 0)
	c[i] += additional_walk
	ans2 += additional_walk
print([ans1, ans2][ans2 < ans1])
print(' '.join(map(str, [b, c][ans2 < ans1])))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i] for i in range(n)]
cnt = 0
for i in range(1, n):
	if b[i - 1] + b[i] < k:
		cnt += k - b[i - 1] - b[i]
		b[i] += k - b[i - 1] - b[i]
print(cnt)
print(*b)


R = lambda : map(int, input().split())
(n, k) = R()
a = list(R())
sa = sum(a)
for i in range(1, n):
	a[i] += max(0, k - a[i] - a[i - 1])
print(sum(a) - sa)
for x in a:
	print(x, end=' ')


(x, y) = map(int, input().split())
li = list(map(int, input().split()))
ans = 0
for i in range(1, x):
	a = li[i] + li[i - 1]
	if a < y:
		li[i] += y - a
		ans += y - a
print(ans)
print(*li)


def best_friend_of_a_man():
	data = [int(x) for x in input().strip().split(' ')]
	days = [int(x) for x in input().strip().split(' ')]
	total = 0
	for i in range(data[0] - 1):
		if days[i] + days[i + 1] >= data[1]:
			continue
		counter = data[1] - (days[i] + days[i + 1])
		days[i + 1] += counter
		total += counter
	print(total)
	print(' '.join((str(x) for x in days)))
best_friend_of_a_man()


import sys, os
from math import sqrt, gcd, ceil, log, floor, sin, pi
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	(n, k) = read()
	arr = read()
	s = 0
	for i in range(1, n):
		t = max(0, k - arr[i - 1] - arr[i])
		s += t
		arr[i] += t
	print(s)
	print(*arr)
main()


(n, k) = map(int, input().split())
a = [int(s) for s in input().split()]
b = [None] * n
b[0] = a[0]
c = 0
for i in range(1, n):
	if b[i - 1] + a[i] < k:
		b[i] = a[i] + (k - (b[i - 1] + a[i]))
		c += k - (b[i - 1] + a[i])
	else:
		b[i] = a[i]
print(c)
print(*b)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
counter = 0
step = 0
for i in range(1, n):
	if s[i] + s[i - 1] < m:
		step = m - s[i] - s[i - 1]
		counter += step
		s[i] += step
print(counter)
print(*s)


I = lambda : map(int, input().split())
(n, m) = I()
d = list(I())
if n == 1:
	print(0)
	print(d[0])
else:
	ans = 0
	for i in range(1, n):
		ans += max(0, m - (d[i] + d[i - 1]))
		d[i] += max(0, m - (d[i] + d[i - 1]))
	print(ans)
	print(' '.join((str(x) for x in d)))


import math
(n, k) = map(int, input().split())
l2 = []
a = list(map(int, input().split()))
for i in a:
	l2.append(i)
i = 1
l = [a[0]]
while i <= n - 1:
	if a[i] + a[i - 1] < k:
		a[i] = k - a[i - 1]
		l.append(k - a[i - 1])
	else:
		l.append(a[i])
	i = i + 1
print(sum(l) - sum(l2))
print(*l)


(n, k) = map(int, input().split())
b = [int(x) for x in input().split()]
s = 0
for i in range(1, n):
	s += max(k - b[i - 1] - b[i], 0)
	b[i] += max(k - b[i - 1] - b[i], 0)
c = [str(x) for x in b]
print(s)
print(' '.join(c))


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		(n, k) = invr()
		a = inlt()
		ans = 0
		for i in range(1, n):
			if a[i] + a[i - 1] < k:
				ans += k - (a[i] + a[i - 1])
				a[i] += k - (a[i] + a[i - 1])
		print(ans)
		print(*a, sep=' ')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
ip = [k]
op = []
count = 0
ip += list(map(int, input().split()))
ip.append(k)
for i in range(n + 1):
	if ip[i + 1] + ip[i] >= k:
		continue
	else:
		temp = ip[i + 1]
		ip[i + 1] = k - ip[i]
		count += k - ip[i] - temp
print(count)
for i in range(1, n + 1):
	print(ip[i], end=' ')


m = input()
n = int(m.split()[0])
k = int(m.split()[1])
m = input()
a = m.split()
b = [0] * n
b[0] = int(a[0])
count = 0
for i in range(1, n):
	try:
		add = k - (int(b[i - 1]) + int(a[i]))
		if add <= 0:
			add = 0
		count += add
		b[i] += int(a[i]) + add
	except:
		break
print(count)
for elem in b:
	print(elem, end=' ')


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
(b, l) = ([0] * n, 0)
b[0] = a[0]
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		b[i + 1] = k - (a[i + 1] + a[i]) + a[i + 1]
		l += k - (a[i + 1] + a[i])
		a[i + 1] = b[i + 1]
	else:
		b[i + 1] = a[i + 1]
print(l)
print(*b, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
c = 0
for i in range(1, len(arr)):
	c += k - min(k, arr[i] + arr[i - 1])
	arr[i] += k - min(k, arr[i] + arr[i - 1])
print(c)
s = ''
for i in arr:
	s += str(i) + ' '
print(s)


from re import split
x = split(' ', input())
n = int(x[0])
k = int(x[1])
a = split(' ', input())
for i in range(n):
	a[i] = int(a[i])
List = [k]
List.extend(a)
List.append(k)
Sum = 0
for i in range(1, n + 1):
	if List[i] + List[i - 1] < k:
		Sum += k - List[i - 1] - List[i]
		List[i] = k - List[i - 1]
print(Sum)
for i in range(1, n + 1):
	print(List[i], end=' ')


(a, m) = map(int, input().split())
s = list(map(int, input().split()))
res = 0
for i in range(0, a - 1):
	if s[i] + s[i + 1] < m:
		res += m - (s[i] + s[i + 1])
		s[i + 1] += m - (s[i] + s[i + 1])
print(res)
print(*s)


[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(1, n):
	d = max(0, k - (a[i] + a[i - 1]))
	a[i] += d
	res += d
print(res)
print(' '.join(map(str, a)))


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
extras = 0
for i in range(1, n):
	extras += max(0, k - (arr[i] + arr[i - 1]))
	arr[i] += max(0, k - (arr[i] + arr[i - 1]))
print(extras)
print(*arr)


(n, k) = map(int, input().split())
num = list(map(int, input().split()))
a = b = 0
ans = [i for i in num]
for i in range(1, n):
	val = max(0, k - ans[i] - ans[i - 1])
	a += val
	ans[i] += val
for i in range(n - 1):
	val = max(0, k - num[i] - num[i + 1])
	b += val
	num[i] += val
	if i == n - 2:
		val = max(0, k - num[i] - num[i + 1])
		b += val
		num[i + 1] += val
if a > b:
	print(b)
	print(*num)
else:
	print(a)
	print(*ans)


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]
(n, k) = inp()
(a, ans) = (arr_inp(), 0)
if n == 1:
	print(0, a[0], sep='\n')
else:
	for i in range(1, n):
		s = sum(a[i - 1:i + 1])
		if s < k:
			a[i] += k - s
			ans += k - s
	print(ans)
	print(*a)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
totalWalks = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		totalWalks += k - (a[i] + a[i - 1])
		a[i] += k - (a[i] + a[i - 1])
print(totalWalks)
for walk in a:
	print(walk, end=' ')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
cont = 0
for i in range(1, n):
	if k > a[i - 1] + a[i]:
		cont += k - a[i - 1] - a[i]
		a[i] += k - a[i - 1] - a[i]
print(cont)
a.extend(['\n'])
for item in a:
	print(str(item) + ' ', end='')


I = lambda : map(int, input().split())
(n, k) = I()
a = [*I()]
r = 0
l = k
for i in range(n):
	y = max(0, k - l - a[i])
	a[i] += y
	r += y
	l = a[i]
print(r)
print(*a)


arr = list(map(int, input().strip().split()))[:2]
(n, k) = (arr[0], arr[1])
arr1 = list(map(int, input().strip().split()))[:n]
count = 0
for i in range(n - 1):
	if arr1[i] + arr1[i + 1] < k:
		count += k - (arr1[i] + arr1[i + 1])
		arr1[i + 1] += k - (arr1[i] + arr1[i + 1])
print(count)
for i in range(n):
	print(arr1[i], end=' ')


__author__ = 'linh'

def main():
	s = input()
	s = list(map(int, s.split()))
	n = s[0]
	k = s[1]
	day = input()
	day = list(map(int, day.split()))
	ext_walk = 0
	for i in range(1, len(day)):
		if day[i] + day[i - 1] < k:
			ext_walk += k - day[i] - day[i - 1]
			day[i] = k - day[i - 1]
	print(ext_walk)
	print(*day)
main()


from sys import stdin, stdout

def ri():
	return map(int, stdin.readline().split())
(n, k) = ri()
a = list(ri())
b = [0 for i in range(n)]
b[0] = a[0]
for i in range(n - 1):
	if k > a[i]:
		need = k - b[i]
		if a[i + 1] > need:
			b[i + 1] = a[i + 1]
		else:
			b[i + 1] = need
	else:
		b[i + 1] = a[i + 1]
s = 0
for i in range(n):
	s += b[i] - a[i]
print(s)
print(*b)


(days, walks) = [int(x) for x in input().strip().split()]
schedule = [int(x) for x in input().strip().split()]
additionalwalks = 0
for i in range(1, len(schedule)):
	morewalks = max(0, walks - (schedule[i] + schedule[i - 1]))
	additionalwalks += morewalks
	schedule[i] += morewalks
print(additionalwalks)
print(' '.join(map(str, schedule)))


(n, m) = map(int, input().strip().split())
L = list(map(int, input().strip().split()))
e = 0
dp = [0 for i in range(n)]
dp[0] = L[0]
for i in range(1, n):
	a = max(L[i], m - dp[i - 1])
	dp[i] = a
	r = a - L[i]
	if r > 0:
		e += r
print(e)
print(*dp)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
for i in range(1, n):
	a[i] += max(0, k - a[i] - a[i - 1])
print(sum(a) - s, ' '.join(map(str, a)), sep='\n')


(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = []
B.append(A[0])
res = 0
for i in range(1, len(A)):
	if B[i - 1] + A[i] < k:
		res += k - B[i - 1] - A[i]
		B.append(k - B[i - 1])
	else:
		B.append(A[i])
print(res)
for b in B:
	print(b, end=' ')


i = lambda : map(int, input().split())
(n, k) = i()
a = list(i())
b = sum(a)
for j in range(n - 1):
	if a[j] + a[j + 1] < k:
		a[j + 1] = k - a[j]
print(sum(a) - b)
print(*a)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = input().split()
count = 0
for i in range(n - 1):
	if int(a[i]) + int(a[i + 1]) < k:
		a[i] = int(a[i])
		count = count + k - a[i] - int(a[i + 1])
		a[i + 1] = k - int(a[i])
print(count)
print(*a)


(n, k) = map(int, input().split())
plan_walks = list(map(int, input().split()))
add = 0
for i in range(1, n):
	diff = k - plan_walks[i] - plan_walks[i - 1]
	if diff > 0:
		plan_walks[i] += diff
		add += diff
print(str(add) + '\n' + ' '.join(map(str, plan_walks)))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0] * n
dp[0] = arr[0]
for i in range(1, len(arr)):
	dp[i] = max(arr[i], k - dp[i - 1])
count = 0
for i in range(n):
	count += abs(dp[i] - arr[i])
print(count)
for i in range(n):
	print(dp[i], end=' ')


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
l = list(map(int, input().strip().split(' ')))
ls = []
ls.append(0)
for i in range(1, n):
	if l[i - 1] + ls[i - 1] + l[i] < k:
		ls.append(k - l[i - 1] - ls[i - 1] - l[i])
	else:
		ls.append(0)
print(sum(ls))
for i in range(n):
	ls[i] += l[i]
print(*ls)


(n, k) = map(int, input().split())
(*a,) = map(int, input().split())
ans = 0
for i in range(1, n):
	d = max(0, k - a[i - 1] - a[i])
	ans += d
	a[i] += d
print(ans)
print(*a)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ch = 0
r = [a[0]]
for i in range(len(a) - 1):
	curr_sum = a[i] + a[i + 1]
	if curr_sum >= k:
		r.append(a[i + 1])
		continue
	ch += k - curr_sum
	a[i + 1] += k - curr_sum
	r.append(a[i + 1])
print(ch)
for i in r:
	print(i, end=' ')
print()


(day, walk) = [int(x) for x in input().split()]
my_list = [int(x) for x in input().split()]
full_lack = 0
for x in range(1, day):
	lack = walk - my_list[x - 1] - my_list[x]
	if lack > 0:
		my_list[x] += lack
		full_lack += lack
print(full_lack)
print(*my_list, sep=' ')


d = 0
(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
for i in range(1, n):
	if nums[i] + nums[i - 1] < k:
		d += k - (nums[i] + nums[i - 1])
		nums[i] += int(k - (nums[i] + nums[i - 1]))
for i in range(n):
	nums[i] = str(nums[i])
print(d)
print(' '.join(nums))


(n, k) = [int(i) for i in input().split()]
a = [int(k) for k in input().split()]
s = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		temp = k - (a[i] + a[i - 1])
		s += temp
		a[i] = k - a[i - 1]
print(s)
print(*a)


x = input().split()
(n, k) = (int(x[0]), int(x[1]))
x = [int(n) for n in input().split()]
add = 0
for (i, v) in enumerate(x):
	if i > 0 and v + x[i - 1] < k:
		x[i] = v + (k - (v + x[i - 1]))
		add = add + (x[i] - v)
print(add, '\n', ' '.join((str(q) for q in x)), sep='')


__author__ = 'Alexander'
import sys
(n, k) = map(int, sys.stdin.readline().split())
a = [int(elem) for elem in sys.stdin.readline().split()]
b = a[:]
additional = 0
for i in range(1, len(b)):
	sum = b[i] + b[i - 1]
	if sum < k:
		b[i] += k - sum
		additional += k - sum
sys.stdout.write(str(additional) + '\n')
for i in b:
	sys.stdout.write(str(i) + ' ')


line = input()
tokens = line.split(' ')
n = int(tokens[0])
k = int(tokens[1])
a = [k]
b = []
line = input()
tokens = line.split(' ')
for i in range(0, n):
	a.append(int(tokens[i]))
total_extra_walks = 0
extra_walk_yesterday = 0
for i in range(1, n + 1):
	walk_in_two_days = a[i] + a[i - 1] + extra_walk_yesterday
	if walk_in_two_days < k:
		extra_walk_today = k - walk_in_two_days
	else:
		extra_walk_today = 0
	total_extra_walks += extra_walk_today
	b.append(a[i] + extra_walk_today)
	extra_walk_yesterday = extra_walk_today
print(total_extra_walks)
line = ''
for i in range(0, len(b)):
	line += str(b[i])
	if i != len(b) - 1:
		line += ' '
print(line)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
lst = [k] + lst
lst.append(k)
S = 0
for i in range(n + 1):
	if lst[i] + lst[i + 1] < k:
		S += k - (lst[i] + lst[i + 1])
		lst[i + 1] += k - (lst[i] + lst[i + 1])
print(S)
print(*lst[1:len(lst) - 1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ewalks = 0
if n == 1:
	print(0)
	print(a[0])
else:
	for i in range(n - 1):
		if a[i] + a[i + 1] < k:
			x = k - (a[i] + a[i + 1])
			ewalks += x
			a[i + 1] += x
	print(ewalks)
	for i in range(n - 1):
		print(a[i], end=' ')
	print(a[-1])


(N, k) = map(int, input().split(' '))
days = list(map(int, input().split(' ')))
s = sum(days)
for i in range(1, len(days)):
	if days[i] + days[i - 1] < k:
		days[i] = k - days[i - 1]
print(sum(days) - s)
print(' '.join((str(d) for d in days)))


(n, k) = map(int, input().split())
a_values = list(map(int, input().split()))
count = 0
for i in range(0, n - 1):
	diff = k - (a_values[i] + a_values[i + 1])
	if diff > 0:
		count += diff
		a_values[i + 1] += diff
print(count)
print(*a_values)


(days, walks) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
for i in range(days):
	if i == days - 1:
		continue
	elif arr[i + 1] + arr[i] < walks:
		count += walks - (arr[i] + arr[i + 1])
		arr[i + 1] += walks - (arr[i] + arr[i + 1])
print(count)
print(*arr)


(n, k) = map(int, input().rstrip().split(' '))
l = list(map(int, input().rstrip().split(' ')))
total = 0
f = n
if n < 2:
	print(0)
	print(l[0])
else:
	for i in range(0, n - 1):
		d = l[i] + l[i + 1]
		if d < k:
			total += k - d
			l[i + 1] += k - d
	if n % 2:
		d = l[-1] + l[-2]
		if d < k:
			total += k - d
			l[-1] += k - d
	print(total)
	for i in l:
		print(i, end=' ')


import os
LOCAL_PC = 'n1amr' in os.path.expanduser('~')

def process_file(in_name, out_name):
	with open(in_name, 'r') as fin:
		with open(out_name, 'w') as fout:

			def read():
				return fin.readline().rstrip('\n')

			def write(*args, end='\n'):
				text = ' '.join(map(str, args)) + end
				fout.write(text)
				print(text, end='')
			t = int(fin.readline())
			for i in range(t):
				read()
				write('Case #{T}: \n'.format(T=i + 1), end='')
				solve(read, write)
				write()

def process_stdio():

	def read():
		return input()

	def write(*args, end='\n'):
		print(*args, end=end)
	solve(read, write)

def solve(input, print):
	(n, k) = map(int, input().split())
	A = [k, *map(int, input().split()), k]
	c = 0
	for i in range(1, len(A) - 1):
		if A[i] + A[i - 1] < k:
			t = k - (A[i] + A[i - 1])
			c += t
			A[i] += t
	print(c)
	print(*A[1:-1])
if LOCAL_PC:
	in_name = __file__[:-3] + '.in'
	out_name = __file__[:-3] + '.out'
	process_file(in_name, out_name)
else:
	process_stdio()


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, k) = MI()
	a = LI()
	c = 0
	for i in range(1, n):
		if a[i - 1] + a[i] < k:
			c += k - (a[i - 1] + a[i])
			a[i] += k - (a[i - 1] + a[i])
	print(c)
	print(*a)
main()


(day_number, k) = map(int, input().split())
plan = list(map(int, input().split()))
addition = 0
for i in range(1, day_number):
	current_addition = k - plan[i] - plan[i - 1]
	if current_addition > 0:
		addition += current_addition
		plan[i] += current_addition
print(addition)
print(*plan)


[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
if n == 1:
	print(0)
	print(a[0])
else:
	b = [a[0]]
	new = a[0]
	s = 0
	for i in range(1, n):
		if a[i] + new < k:
			new = k - new
			s += new - a[i]
		else:
			new = a[i]
		b.append(new)
	print(s)
	for i in range(n):
		print(b[i], end=' ')


(n, k) = map(int, input().split())
walks = list(map(int, input().split()))
i = 1
b = [walks[0]]
count = 0
while i < len(walks):
	if b[i - 1] + walks[i] < k:
		temp = k - b[i - 1]
		b.append(temp)
		count = count + temp - walks[i]
	else:
		b.append(walks[i])
	i = i + 1
print(count)
print(*b)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
cost = 0
for i in range(1, n):
	x = a[i] + a[i - 1]
	if x < k:
		a[i] += k - x
		cost += k - x
print(cost)
print(*a)


[n, k] = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
res = 0
s = str(q[0]) + ' '
for i in range(n - 1):
	if q[i] + q[i + 1] < k:
		res += k - q[i + 1] - q[i]
		q[i + 1] += k - q[i + 1] - q[i]
	s += str(q[i + 1])
	s += ' '
print(res)
print(s)


from collections import defaultdict
from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
ans = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		ans += k - a[i] - a[i + 1]
		a[i + 1] = k - a[i]
print(ans)
print(*a)


(n, k) = list(map(int, input().split()))
ls = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	s = ls[i] + ls[i + 1]
	d = k - s
	if s < k:
		ls[i + 1] += d
		ans += d
print(ans)
for a in ls:
	print(a, end=' ')


(N, K) = (int(x) for x in input().split())
walklist = [int(x) for x in input().split()]
cost = 0
for i in range(1, N):
	if walklist[i] + walklist[i - 1] < K:
		cost += K - (walklist[i] + walklist[i - 1])
		walklist[i] = K - walklist[i - 1]
print(cost)
print(' '.join([str(x) for x in walklist]))


(n, k) = map(int, input().split())
ls = list(map(int, input().split())) + [k]
c = 0
for i in range(1, n + 1):
	val = max(0, k - (ls[i] + ls[i - 1]))
	c += val
	ls[i] += val
print(c)
print(*ls[:-1])


def main():
	(n, k) = map(int, input().split())
	a_list = list(map(int, input().split()))
	initial = sum(a_list)
	for i in range(1, len(a_list)):
		if a_list[i - 1] + a_list[i] < k:
			a_list[i] += k - (a_list[i - 1] + a_list[i])
	print(sum(a_list) - initial)
	print(*a_list)
main()


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
prevDebt = 0
suma = 0
result = []
for val in v:
	debt = prevDebt - val
	if debt <= 0:
		result.append(str(val))
		prevDebt = k - val
	else:
		result.append(str(val + debt))
		suma += debt
		prevDebt = k - val - debt
print(suma)
print(' '.join(result))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
dop = 0
for i in range(n - 1):
	if a[i] + a[i + 1] < k:
		z = k - (a[i] + a[i + 1])
		dop += z
		a[i + 1] += z
print(dop)
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
add = 0
for i in range(1, n):
	s = arr[i] + arr[i - 1]
	miss = max(k - s, 0)
	add += miss
	arr[i] += miss
print(add)
print(*arr)


(n, k) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
totalAddedWalks = 0
for i in range(len(a) - 1):
	if a[i] + a[i + 1] < k:
		ExtraWalksReq = k - (a[i] + a[i + 1])
		totalAddedWalks = totalAddedWalks + ExtraWalksReq
		a[i + 1] = a[i + 1] + ExtraWalksReq
print(totalAddedWalks)
for ans in a:
	print(ans, end=' ')


c = 0
(n, k) = input().split()
(n, k) = (int(n), int(k))
one = [int(i) for i in input().split()]
for i in range(len(one) - 1):
	if one[i] + one[i + 1] < k:
		c += k - (one[i] + one[i + 1])
		one[i + 1] = one[i + 1] + (k - (one[i] + one[i + 1]))
print(c)
for i in one:
	print(i, end=' ')


(n, k) = map(int, input().split())
pro = list(map(int, input().split()))
if n == 1:
	print('0')
	print(pro[0])
else:
	ll = [str(pro[0])]
	j = 0
	for i in range(1, n):
		if int(ll[-1]) + pro[i] < k:
			j += k - int(ll[-1]) - pro[i]
			ll.append(str(k - int(ll[-1])))
		else:
			ll.append(str(pro[i]))
	print(j)
	print(' '.join(ll))


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
count = 0
for i in range(n - 1):
	if l[i] + l[i + 1] < k:
		temp = k - (l[i] + l[i + 1])
		count += temp
		l[i + 1] += temp
print(count)
st = ''
for i in l:
	st += str(i) + ' '
print(st)


(n, k) = list(map(int, input().split()))
a = []
a.append(k)
b = list(map(int, input().split()))
for i in b:
	a.append(i)
count = 0
for i in range(1, n + 1):
	if a[i] + a[i - 1] < k:
		count += k - (a[i] + a[i - 1])
		a[i] += k - (a[i] + a[i - 1])
print(count)
del a[0]
print(*a, sep=' ')


num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
k = int(num_input[1])
arr = input()
arr = arr.split(' ')
for i in range(0, len(arr)):
	arr[i] = int(arr[i])
dp = [arr[0]]
for i in range(1, len(arr)):
	if arr[i] + dp[i - 1] >= k:
		dp.append(arr[i])
	else:
		dp.append(k - dp[i - 1])
count = 0
for i in range(0, len(arr)):
	count += abs(arr[i] - dp[i])
for i in range(0, len(arr)):
	dp[i] = str(dp[i])
res = ' '.join(dp)
print(count)
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
soa = sum(a)
for i in range(0, n - 1):
	if sum(a[i:i + 2]) < k:
		a[i + 1] = k - a[i]
print(sum(a) - soa)
print(*a)


import math
a = list(map(int, input().split()))
n = a[0]
k = a[1]
a = list(map(int, input().split()))
total = 0
for i in range(1, n):
	if a[i] + a[i - 1] < k:
		total += k - (a[i] + a[i - 1])
		a[i] += k - (a[i] + a[i - 1])
print(total)
for i in range(n):
	print(a[i], end=' ')


from bisect import bisect_right as br
import sys
from collections import *
from math import *
import re

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	c = 0
	for i in range(2, n):
		if prime[i]:
			c += 1
	return c

def iseven(n):
	return [False, True][0 if n % 2 else 1]

def inp_arr():
	return list(map(int, input().split()))

def inp():
	return map(int, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
max_int = sys.maxsize
mod = 10 ** 9 + 7
(n, k) = inp()
arr = inp_arr()
(out_arr, res) = ([0] * n, 0)
out_arr[0] = arr[0]
for i in range(1, n):
	out_arr[i] = max(k - out_arr[i - 1], arr[i])
	res += abs(out_arr[i] - arr[i])
print(res)
print(*out_arr)


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
const = arr[0]
ans = 0
for i in range(1, n):
	if const + arr[i] < k:
		ans += k - const - arr[i]
		arr[i] = arr[i] + k - (const + arr[i])
	const = arr[i]
print(ans)
print(*arr)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(n - 1):
	m = a[i] + a[i + 1]
	if m < k:
		cnt += k - m
		a[i + 1] += k - m
print(cnt)
for p in a:
	print(p, end=' ')


raw = input().split()
n = int(raw[0])
k = int(raw[1])
raw = input().split()
a = [int(raw[i]) for i in range(n)]
if n == 2:
	d = k - (a[0] + a[1])
	print(max(d, 0))
	print(a[0], end=' ')
	print(a[1] + max(d, 0))
	quit()
elif n == 1:
	d = 0
	print(max(d, 0))
	print(a[0])
	quit()
mins = [a[i] for i in range(n)]
maxs = [a[i] for i in range(n)]
sum = sum(a)
dmin = mins[0]
dmax = maxs[0]
for i in range(1, n):
	mins[i] = max(k - maxs[i - 1], mins[i])
	dmin += mins[i]
	maxs[i] = max(k - mins[i - 1], maxs[i])
	dmax += maxs[i]
dmin -= sum
dmax -= sum
isMin = dmin > dmax
if isMin:
	print(dmin)
else:
	print(dmax)
if n % 2 == 0:
	isMin = not isMin
for i in range(n):
	if isMin:
		print(mins[i], end=' ')
	else:
		print(maxs[i], end=' ')
	isMin = not isMin