#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 5;
int f[N * 4];
int a[N];
void updt(int rt, int l, int r, int x, int op) {
  if (l == r) {
    f[rt] = op;
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid) updt(rt << 1, l, mid, x, op);
  if (mid + 1 <= x) updt(rt << 1 | 1, mid + 1, r, x, op);
  f[rt] = max(f[rt << 1], f[rt << 1 | 1]);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return f[rt];
  int mid = (l + r) / 2, mx = 0;
  if (mid >= L) mx = max(mx, query(rt << 1, l, mid, L, R));
  if (mid + 1 <= R) mx = max(mx, query(rt << 1 | 1, mid + 1, r, L, R));
  return mx;
}
int main() {
  int n, k, res = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int l = max(0, a[i] - k), r = min(a[i] + k, 300000);
    int mx = query(1, 1, 300000, l, r);
    printf("%d %d %d\n", l, r, query(1, 1, 300000, l, r));
    updt(1, 1, 300000, a[i], mx + 1);
    res = max(res, mx + 1);
  }
  printf("%d\n", res);
}
