#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans += max(0, k - a[i] - a[i - 1]);
    a[i] += max(0, k - a[i] - a[i - 1]);
  }
  cout << ans << '\n';
  for (auto x : a) cout << x << " ";
  cout << endl;
  ;
}
int main() {
  int t = 1;
  while (t--) solve();
}
