#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int dp[n][2];
  for (int i = 0; i < n; ++i) {
    dp[i][0] = dp[i][1] = 1;
  }
  int maxi[n];
  dp[0][0] = 0;
  dp[0][1] = 1;
  if (n > 1) {
    dp[1][0] = 1;
    maxi[1] = arr[0];
    if (abs(arr[1] - arr[0]) <= k) {
      dp[1][1] = 2;
    } else
      dp[1][1] = 1;
  }
  for (int i = 2; i < n; ++i) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
    maxi[i] = maxi[i - 1];
    if (abs(arr[i] - arr[i - 1]) <= k) {
      maxi[i] = arr[i];
      dp[i][1] = dp[i - 1][1] + 1;
    }
    if (abs(maxi[i] - arr[i]) <= k) {
      if (dp[i][1] <= dp[i - 1][0] + 1) {
        dp[i][1] = dp[i - 1][0] + 1;
        maxi[i] = arr[i];
      }
    }
  }
  vector<int> v;
  int ans = max(dp[n - 1][1], dp[n - 1][0]);
  int prev = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (dp[i][1] == ans) {
      if (prev == -1) {
        ans--;
        v.push_back(arr[i]);
        prev = arr[i];
      } else if (abs(arr[i] - prev) <= k) {
        ans--;
        v.push_back(arr[i]);
        prev = arr[i];
      }
    }
  }
  for (int i = v.size() - 1; i >= 0; --i) {
    cout << v[i] << " ";
  }
  return 0;
}
