#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ans = 0;
  if (n < 3) {
    if (n == 2) {
      ans = (k - (v[0] + v[1])) > 0 ? (k - (v[0] + v[1])) : 0;
      v[1] += ans;
    }
  } else {
    for (int i = 1, add; i < n; i++) {
      add = max(0, k - v[i] - v[i - 1]);
      ans += add;
      v[i] += add;
    }
  }
  cout << ans << endl;
  for (auto s : v) cout << s << " ";
  return 0;
}
