#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long A[n];
  for (long long i = 0; i < n; i++) cin >> A[i];
  long long ans[n], cnt = 0;
  ans[0] = A[0];
  for (long long i = 1; i < n; i++) {
    if (A[i] + ans[i - 1] < k) {
      ans[i] = k - ans[i - 1];
      cnt += (k - ans[i - 1] - A[i]);
    } else
      ans[i] = A[i];
  }
  cout << cnt << endl;
  for (long long i = 0; i < n; i++) cout << ans[i] << " ";
}
