#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
long long a[maxn];
int main() {
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] + a[i - 1] < k) {
      ans += (k - a[i] - a[i - 1]);
      a[i] = k - a[i - 1];
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << '\n';
}
