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: interview

Starter code:

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

ans = 0
for i in range(1, n):
    diff = k - (a[i] + a[i - 1])
    if diff > 0:
        a[i] += diff
        ans += diff

print(ans)
print(' '.join(map(str, a)))



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())
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=" ")


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, k = map(int, input().split())
A = list(map(int, input().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] + A[i + 1])
print(ans)
for i in range(n):
	print(A[i], end=' ')


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))))


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)

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]))


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

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

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)))


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


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]))


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().split())
num = list(map(int, input().split()))

ans = 0

for i in range(1,n):
    if num[i]+num[i-1]<k:
        ans += k-(num[i]+num[i-1])
        num[i] = k-num[i-1]

print(ans)
print(' '.join([str(x) for x in num]))

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

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))


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

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

result = 0

for i in range(1, n):
    if a[i] + a[i-1] < k:
        result += k - a[i] - a[i-1]
        a[i] = (k - a[i-1])
print(result)
print(" ".join(map(str, a)))


n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i 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]
print(c)
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, k = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
c = 0
for i in range(1, n):
    if l[i-1] + l[i] < k:
        a = k - (l[i-1] + l[i])
        c += a
        l[i] += a
print(c)
print(' '.join(str(i) for i in l))


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

from collections import defaultdict
import sys, os, math

def __starting_point():
    #n, m = list(map(int, input().split()))
    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()

def __starting_point():
    #n = 4
    #k = 6
    #a = [2, 4, 3, 5]
    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()

def do():
    n,k = list(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] # check if i+1 > n
        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])