#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int days, walks, count = 0;
  cin >> days >> walks;
  int walk[days];
  for (int i = 0; i < days; ++i) cin >> walk[i];
  for (int i = 1; i < days; ++i) {
    if (walk[i] + walk[i - 1] < walks) {
      count += walks - walk[i - 1] - walk[i];
      walk[i] = walks - walk[i - 1];
    }
  }
  cout << count << '\n';
  for (int i = 0; i < days - 1; ++i) cout << walk[i] << ' ';
  cout << walk[days - 1] << '\n';
  return 0;
}
