#include <bits/stdc++.h>
using namespace std;
string solution(string s) {
  string ret = s;
  long long int n = s.size();
  long long int c = n - 1;
  for (int i = 0; i < n / 2; i++) {
    ret[i] = s[c - 1];
    ret[n - i - 1] = s[c];
    c -= 2;
  }
  if (n & 1) ret[n / 2] = s[0];
  cout << ret << endl;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v(n), m1(n), m2(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long int ma1 = 0, ma2 = 0;
  m1 = v;
  m2 = v;
  for (int i = 0; i < n - 1; i++) {
    if (m1[i] + m1[i + 1] < k) {
      ma1 += k - (m1[i] + m1[i + 1]);
      m1[i + 1] += k - (m1[i] + m1[i + 1]);
    }
  }
  cout << ma1 << endl;
  for (int i = 0; i < n; i++) {
    cout << m1[i] << " ";
  }
}
