#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int arr[n];
  int prr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  prr[0] = arr[0];
  int diff = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i] + arr[i + 1] < k) {
      diff += abs(k - (arr[i] + arr[i + 1]));
      arr[i + 1] = k - arr[i];
    }
  }
  cout << diff << "\n";
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }
  return 0;
}
