#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[1005];
  for (long long int i = 0; i < n; i += 1) cin >> arr[i];
  long long int res[1005], res1 = 0;
  res[n - 1] = arr[n - 1];
  for (long long int j = n - 2; j >= 0; j--) {
    res[j] = max(k - res[j + 1], arr[j]);
  }
  for (long long int i = 0; i < n; i += 1) res1 += res[i] - arr[i];
  cout << res1 << endl;
  for (long long int i = 0; i < n; i += 1) cout << res[i] << " ";
  return 0;
}
