#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500;
int arr[MAX_N + 10];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  int acc = 0;
  for (int i = 1; i < n; i++) {
    int m = max(0, k - arr[i - 1]);
    int x = max(0, m - arr[i]);
    arr[i] += x;
    acc += x;
  }
  cout << acc << endl;
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << arr[i];
  }
  cout << endl;
  return 0;
}
