#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 3e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int& i : v) cin >> i;
  int c = 0;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] + v[i + 1] >= k) continue;
    int sum = v[i] + v[i + 1];
    c += (k - sum);
    if (i == n - 2 && v[i] > v[i + 1])
      v[i] += (k - sum);
    else
      v[i + 1] = (k - v[i]);
  }
  cout << c << "\n";
  for (int& i : v) cout << i << " ";
  return 0;
}
