#include <bits/stdc++.h>
using namespace std;
const int MIN = 1e3 + 2;
const int MXN = 1e6 + 3;
const int INF = 1e9 + 7;
const long long LINF = 1e18 + 15;
const double EPS = 1e-9;
string st;
int a[MXN], b[MXN], cnt, n, m, ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] + a[i - 1] < m) {
      ans += m - (a[i] + a[i - 1]);
      a[i] = m - a[i - 1];
    }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
