#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int *a = new int[n];
  int before;
  cin >> before;
  a[0] = before;
  int count = 0;
  for (int i = 1; i < n; i++) {
    int curr;
    cin >> curr;
    if (before + curr < m) {
      int diff = m - before - curr;
      count += diff;
      curr += diff;
      a[i] = curr;
    } else {
      a[i] = curr;
    }
    before = curr;
  }
  cout << count << "\n";
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
