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