#include <bits/stdc++.h>
const int maxn = 1000;
int a[maxn], b[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] + a[i - 1] < k) {
      ans += k - a[i] - a[i - 1];
      a[i] = k - a[i - 1];
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; ++i) {
    if (i == 0)
      printf("%d", a[i]);
    else
      printf(" %d", a[i]);
  }
  printf("\n");
  return 0;
}
