#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, sum = 0, sum1 = 0, index = 0;
  cin >> n >> k;
  int* a = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int* b = new int[n];
  int x = 0;
  int z = 0;
  b[index++] = a[0];
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i - 1] < k)
      z = k - (a[i] + a[i - 1]);
    else
      z = 0;
    a[i] += z;
    b[index++] = a[i];
    sum1 += a[i];
  }
  cout << sum1 + a[0] - sum;
  cout << endl;
  for (int i = 0; i < n; i++) cout << b[i] << " ";
}
