#include <bits/stdc++.h>
using namespace std;
int day[505];
int main() {
  int k, n;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &day[i]);
  }
  int sum = 0;
  for (int i = 1; i < n; i++) {
    if (k - day[i] - day[i + 1] < 0) {
      sum += 0;
    } else {
      sum += k - day[i] - day[i + 1];
      day[i + 1] = k - day[i];
    }
  }
  printf("%d\n", sum);
  for (int i = 1; i < n; i++) printf("%d ", day[i]);
  printf("%d", day[n]);
  return 0;
}
