#include <bits/stdc++.h>
using namespace std;
int walks[501];
void solve(int n, int k) {
  int additional = 0;
  for (int i = 1; i < n; i++) {
    if (walks[i - 1] + walks[i] < k) {
      additional += k - (walks[i - 1] + walks[i]);
      walks[i] += k - (walks[i - 1] + walks[i]);
    }
  }
  cout << additional << "\n";
  for (int i = 0; i < n; i++) {
    if (i != n - 1) {
      cout << walks[i] << " ";
    } else {
      cout << walks[i];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int elem, k;
  cin >> elem >> k;
  for (int i = 0; i < elem; i++) {
    int n;
    cin >> n;
    walks[i] = n;
  }
  solve(elem, k);
  return 0;
}
