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