#include <bits/stdc++.h>
using namespace std;
int n, k;
int arr[501], dp[501][501], sol[501][501];
int solve(int d = 0, int a = 0) {
  if (d == n - 1) {
    dp[d][a] = 0;
    return 0;
  }
  int &ret = dp[d][a];
  if (~ret) return ret;
  int t = arr[d] + arr[d + 1] + a;
  if (t < k) {
    int s1 = solve(d + 1, 0), s2 = solve(d + 1, k - t);
    if (s1 < s2) {
      sol[d][a] = 0;
    } else {
      sol[d][a] = k - t;
    }
    ret = k - t + min(s1, s2);
  } else {
    sol[d][a] = 0;
    ret = solve(d + 1, 0);
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  memset(sol, -1, sizeof sol);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  int ans = solve();
  cout << ans << endl << arr[0] << " ";
  int j = sol[0][0];
  for (int i = 1; i < n; ++i) {
    int t = ans - dp[i][j];
    ans = dp[i][j];
    j = sol[i][j];
    cout << arr[i] + t << " ";
  }
}
