#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k, x;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] + a[i + 1] < k) {
      int t = k - a[i];
      ans += (t - a[i + 1]);
      a[i + 1] = t;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
