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