#include <bits/stdc++.h>
using namespace std;
long long n, m, k, k1, a[10000000], b[10000000], ans, ans1;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] + a[i - 1] < k) a[i] = k - a[i - 1];
  }
  for (int i = 1; i <= n; i++) ans1 = ans1 + a[i];
  cout << ans1 - ans << endl;
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
}
