#include <bits/stdc++.h>
using namespace std;
set<long long> s;
set<long long>::iterator it;
vector<long long> v;
int n;
int main() {
  int i, j, t, k;
  int a[1005];
  ;
  scanf("%d%d", &n, &k);
  ;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  int ans = 0;
  for (i = n - 1; i >= 1; i--) {
    int x = a[i] + a[i + 1];
    int diff = k - x;
    if (diff < 0)
      continue;
    else {
      ans += diff;
      a[i] += diff;
    }
  }
  printf("%d\n", ans);
  for (i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
