#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n], af1[n], af2[n], add2 = 0, add = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  af1[0] = arr[0];
  for (int i = 1; i < n; ++i) {
    if ((af1[i - 1] + arr[i]) < k) {
      af1[i] = k - af1[i - 1];
      add += af1[i] - arr[i];
    } else
      af1[i] = arr[i];
  }
  af2[n - 1] = arr[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    if ((af2[i + 1] + arr[i]) < k) {
      af2[i] = k - af2[i + 1];
      add2 += af2[i] - arr[i];
    } else
      af2[i] = arr[i];
  }
  if (add2 < add) {
    cout << add2 << '\n';
    for (int i = 0; i < n; ++i) cout << af2[i] << " ";
  } else {
    cout << add << '\n';
    for (int i = 0; i < n; ++i) cout << af1[i] << " ";
  }
  return 0;
}
