#include <bits/stdc++.h>
using namespace std;
int n, k, mas[1000], ans[1000], anss;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> mas[i];
  for (int i = 2; i <= n; i++) {
    if (mas[i] + mas[i - 1] < k) {
      anss += k - mas[i - 1] - mas[i];
      mas[i] = k - mas[i - 1];
    }
  }
  cout << anss << "\n";
  for (int i = 1; i <= n; i++) cout << mas[i] << ' ';
}
