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