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