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