#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], count = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (a[i - 1] + a[i] < k) {
      int old = a[i];
      a[i] = k - a[i - 1];
      count += a[i] - old;
    }
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}
