#include <bits/stdc++.h>
using namespace std;
long long int pwr(long long int n, long long int m) {
  if (n == 1 || m == 0) return 1;
  long long int x = pwr(n, m / 2);
  if (m % 2 == 0)
    return x * x;
  else
    return n * x * x;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int ans = 0, rem = 0, done = 0;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  done = a[0];
  for (long long int i = 1; i < n; i++) {
    done += a[i];
    if (done <= k) a[i] += k - done, ans += k - done;
    done = a[i];
  }
  cout << ans << "\n";
  for (long long int i = 0; i < n; i++) cout << a[i] << " ";
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) solve();
  cerr << '\n'
       << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
