#include <bits/stdc++.h>
using namespace std;
void io() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  long long int n, k;
  scanf("%lld%lld", &n, &k);
  long long int dif = 0, temp;
  long long int *a = new long long int[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int *b = new long long int[n];
  b[0] = a[0];
  for (long long int i = 1; i < n; i++) {
    temp = k - b[i - 1];
    if (temp <= a[i])
      b[i] = a[i];
    else
      b[i] = temp;
    dif += b[i] - a[i];
  }
  printf("%lld\n", dif);
  for (long long int i = 0; i < n; i++) printf("%lld ", b[i]);
  cout << endl;
  delete[] a;
  delete[] b;
  return 0;
}
