#include <bits/stdc++.h>
using namespace std;
int mem[1003][1003];
int n, k;
int num[1003];
int dp(int idx, int prev = k) {
  if (idx == n) {
    return 0;
  }
  int &ret = mem[idx][prev];
  if (ret != -1) {
    return ret;
  }
  ret = 1e9;
  for (int i = 0; i <= k; i++) {
    if (prev + i + num[idx] >= k) ret = min(ret, dp(idx + 1, num[idx] + i) + i);
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }
  memset(mem, -1, sizeof mem);
  int answer = dp(0);
  int prev = k;
  cout << answer << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      if (num[i] + j + prev >= k) {
        if (dp(i + 1, num[i] + j) == answer - j) {
          cout << num[i] + j << " ";
          prev = num[i] + j;
          answer -= j;
          break;
        }
      }
    }
  }
}
