#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e5;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (auto& x : v) cin >> x;
  auto ans = 0;
  vector<int> res;
  for (int i(1); i < n; ++i) {
    auto x = v[i - 1] + v[i];
    ans += max(k - x, 0);
    if (k - x > 0)
      res.emplace_back(k - x), v[i] += k - x;
    else
      res.emplace_back(v[i]);
  }
  cout << ans << endl;
  for (auto& x : v) cout << x << " ";
  cout << endl;
}
