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