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