#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int INF = 1e9 + 5;
const int N = 2e5 + 20;
void solve() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> v(n + 1, 0), v1(n + 1, 0), v2(n + 1, 0);
  for (int i = 1; i <= n; ++i) cin >> v[i];
  for (int i = 2; i <= n; ++i) {
    ans += max(0, k - v[i] - v[i - 1]);
    v[i] += max(0, k - v[i] - v[i - 1]);
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; ++i) cout << v[i] << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
