#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> b(n + 1);
  b[1] = a[1];
  int res = 0;
  for (int i = 2; i <= n; i++) {
    int walks_today = k - (b[i - 1] + a[i]);
    if (walks_today <= 0) {
      b[i] = a[i];
    } else {
      b[i] = a[i] + walks_today;
      res += walks_today;
    }
  }
  cout << res << "\n";
  for (int i = 1; i <= n; i++) cout << b[i] << " ";
  return 0;
}
