#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (auto &x : v) cin >> x;
  int dp[n];
  dp[0] = v[0];
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = max(k - dp[i - 1], v[i]);
  }
  for (int i = 0; i < n; i++) {
    cnt += dp[i] - v[i];
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) cout << dp[i] << " ";
  return 0;
};
