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