#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch <= '9' && ch >= '0'; x = x * 10 + ch - 48, ch = getchar())
    ;
  return x;
}
int i, j, k, m, n, x, y, a[550], b[550], ans;
int main() {
  for (n = read(), k = read(), i = 1; i <= n; ++i) a[i] = read();
  for (b[1] = a[1], i = 2; i <= n; ++i)
    if (a[i] + b[i - 1] < k)
      ans += k - a[i] - b[i - 1], b[i] = k - b[i - 1];
    else
      b[i] = a[i];
  printf("%d\n", ans);
  for (i = 1; i <= n; ++i) printf("%d ", b[i]);
}
