#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  vector<int> hasil(arr);
  long long total = 0;
  if (n == 2) {
    if (k > arr[1] + arr[0]) {
      long long hasil = k - arr[0];
      arr[1] = arr[1] + max((long long)0, hasil - arr[1]);
      if (arr[0] + arr[1] < k) arr[0] = arr[0] + (k - (arr[1] + arr[0]));
    }
  }
  for (int i = 1; i < n - 1; i++) {
    if (k > arr[i] + arr[i + 1] || k > arr[i] + arr[i - 1]) {
      long long hasil = min(k - arr[i + 1], k - arr[i - 1]);
      arr[i] = arr[i] + max((long long)0, hasil - arr[i]);
      if (arr[i - 1] + arr[i] < k)
        arr[i - 1] = arr[i - 1] + (k - (arr[i] + arr[i - 1]));
      if (arr[i + 1] + arr[i] < k)
        arr[i + 1] = arr[i + 1] + (k - (arr[i] + arr[i + 1]));
    }
  }
  for (int i = 0; i < n; ++i) {
    total += arr[i] - hasil[i];
  }
  cout << total << endl;
  for (int i = 0; i < n; ++i) {
    cout << arr[i] << " ";
  }
  return 0;
}
