#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, sum = 0;
  cin >> n >> k;
  int ar[n];
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (i = 1; i < n; i++) {
    (k - ar[i] - ar[i - 1] > 0) ? sum += k - ar[i] - ar[i - 1] : sum += 0;
    ar[i] += max(0, k - ar[i] - ar[i - 1]);
  }
  cout << sum << "\n";
  for (i = 0; i < n; i++) {
    cout << ar[i] << " ";
  }
  cout << "\n";
  return 0;
}
