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