#include <bits/stdc++.h>
using namespace std;
unsigned long long fib[100010];
long bigmod(long a, unsigned long long p, long m) {
  if (p == 0) return 1;
  if (p & 1) {
    return ((a % m) * (bigmod(a, p - 1, m))) % m;
  } else {
    unsigned long long tmp = bigmod(a, p / 2, m);
    return (tmp * tmp) % m;
  }
}
void f() {
  fib[0] = 2;
  fib[1] = 3;
  for (int i = 2; i <= 100005; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
}
int main() {
  int n, m;
  int a[510];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if ((a[i] + a[i + 1]) < m) {
      ans += (m - (a[i] + a[i + 1]));
      a[i + 1] += (m - (a[i] + a[i + 1]));
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
