#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int mini = INT_MAX;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    b[i] = a[i];
    a[i] = ((k - a[i - 1]) > a[i]) ? (k - a[i - 1]) : a[i];
  }
  b[0] = a[0];
  int sum = 0;
  for (int i = 0; i < n; i++) sum += a[i] - b[i];
  cout << sum << endl;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
