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