#include <bits/stdc++.h>
using namespace std;
const long long N = 1e12;
int fexp(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 998244353;
    b /= 2;
    a = a * a % 998244353;
  }
  return ans;
}
int inverse(int a, int p) { return fexp(a, p - 2); }
long long solve() { return 0; }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, n;
  cin >> a >> n;
  long long ans = 0;
  vector<long long> v(a, 0);
  for (long long i = 0; i < a; i++) {
    cin >> v[i];
    if (i) {
      if (v[i] < n - v[i - 1]) {
        ans += n - v[i - 1] - v[i];
        v[i] = n - v[i - 1];
      }
    }
  }
  cout << ans << "\n";
  for (long long i = 0; i < a; i++) cout << v[i] << " ";
  return 0;
}
