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