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