#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int main(void) {
  int n, k, a[maxn], sum = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 2; i <= n; i++) {
    if (a[i] + a[i - 1] >= k)
      continue;
    else if (a[i] + a[i - 1] < k) {
      sum += k - a[i] - a[i - 1];
      a[i] = k - a[i - 1];
    }
  }
  cout << sum << endl;
  for (int i = 1; i <= n; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}
