#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <class X,
          X (*fxx)(X, X),
          X (*iex)(),
          class Y,
          Y (*fyy)(Y, Y),
          Y (*iey)(),
          X (*fxy)(X, Y)>
class LazySegmentTree {
public:
    vector<X> data;
    vector<Y> lazy;
    int orgSize;
    int size;

    LazySegmentTree(int n) : orgSize(n) {
        auto v = vector<X>(n, iex());
        initialize(v);
    }

    LazySegmentTree(vector<X> &v) : orgSize((int)v.size()) {
        initialize(v);
    }

    LazySegmentTree(vector<X> &&v) : LazySegmentTree(v) {}

    void initialize(vector<X> &v) {
        size = 1;
        while (size < orgSize)
            size *= 2;
        data.resize(2 * size - 1, iex());
        lazy.resize(2 * size - 1, iey());

        for (int i = 0; i < orgSize; i++)
            data[i + size - 1] = v[i];

        for (int i = size - 2; i >= 0; i--)
            data[i] = fxx(data[i * 2 + 1], data[i * 2 + 2]);
    }

    void lazyEvaluate(int k) {
        if (lazy[k] != iey()) {
            data[k] = fxy(data[k], lazy[k]);
            if (k < size - 1) {
                lazy[k * 2 + 1] = fyy(lazy[k * 2 + 1], lazy[k]);
                lazy[k * 2 + 2] = fyy(lazy[k * 2 + 2], lazy[k]);
            }
            lazy[k] = iey();
        }
    }

    void apply(int index) {
        return apply(index, index + 1);
    }

    void apply(int a, int b, Y y, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = size;
        lazyEvaluate(k);
        if (b <= l || r <= a)
            return;
        if (a <= l && r <= b) {
            lazy[k] = fyy(lazy[k], y);
            lazyEvaluate(k);
        } else {
            apply(a, b, y, 2 * k + 1, l, (l + r) / 2);
            apply(a, b, y, 2 * k + 2, (l + r) / 2, r);
            data[k] = fxx(data[2 * k + 1], data[2 * k + 2]);
        }
    }

    X query(int index) {
        return query(index, index + 1);
    }

    X query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = size;
        lazyEvaluate(k);
        //dump(a, b, l, r, k, data[k]);
        if (b <= l || r <= a)
            return iex();
        if (a <= l && r <= b)
            return data[k];
        X vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        X vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        //dump(a, b, l, r, k, data[k], vl, vr);
        return fxx(vl, vr);
    }

    void debug() {
#ifdef LOCAL
        cout << "debug : ";
        for (int i = 0; i < orgSize; i++) {
            cout << query(i) << (i != orgSize - 1 ? " " : "");
        }
        cout << endl;
#endif
    }

    void debugALL() {
#ifdef LOCAL
        cout << "--------start--------" << endl;
        for (int i = 0; i < 2 * size - 1; i++)
            lazyEvaluate(i);
        long long cnt = 1;
        for (int i = 0; i < 2 * size - 1; i++) {
            cout << data[i];
            if (i == cnt - 1) {
                cout << endl;
                cnt = cnt * 2 + 1;
            } else {
                cout << " ";
            }
        }
        cout << "---------end---------" << endl;
#endif
    }
};

//Range Minimum Query and Range Update Apply
namespace RMQRUA {
    using X = int;
    X iex() { return 0; }
    X fxx(X x1, X x2) { return max(x1, x2); }
    using Y = int;
    Y iey() { return 0; }
    Y fyy(Y y1, Y y2) { return max(y1, y2); }
    X fxy(X x1, Y y1) { return max(x1, y1); }
    using LST = LazySegmentTree<X, fxx, iex, Y, fyy, iey, fxy>;
} // namespace RMQRUA

//Range Minimum Query and Range Add Apply
namespace RMQRAA {
    using X = int;
    X iex() { return numeric_limits<X>::max(); }
    X fxx(X x1, X x2) { return min(x1, x2); }
    using Y = int;
    Y iey() { return 0; }
    Y fyy(Y y1, Y y2) { return y1 + y2; }
    X fxy(X x1, Y y1) {
        if (x1 == iex())
            return x1;
        return x1 + y1;
    }
    using LST = LazySegmentTree<X, fxx, iex, Y, fyy, iey, fxy>;
} // namespace RMQRAA

//Range Sum Query and Range Update Apply
namespace RSQRUA {
    using X = int;
    X iex() { return 0; }
    X fxx(X x1, X x2) { return x1 + x2; }
    using Y = int;
    Y iey() { return 0; }
    Y fyy(Y y1, Y y2) { return y2; }
    X fxy(X x1, Y y1) { return y1; }
    using LST = LazySegmentTree<X, fxx, iex, Y, fyy, iey, fxy>;
} // namespace RSQRUA

//Range Sum Query and Range Add Apply
namespace RSQRAA {
    using X = pair<int, int>;
    X iex() { return {0, 0}; }
    X fxx(X x1, X x2) { return {max(x1.first, x2.first), x1.second + x2.second}; }
    using Y = int;
    Y iey() { return 0; }
    Y fyy(Y y1, Y y2) { return y1 + y2; }
    X fxy(X x1, Y y1) { return {chmax(x1.first, x1.first + x1.second * y1), x1.second}; }
    using LST = LazySegmentTree<X, fxx, iex, Y, fyy, iey, fxy>;
} // namespace RSQRAA
ostream &operator<<(ostream &os, RSQRAA::X x) {
    os << x.first;
    return os;
}

signed main() {
    INIT;
    cin >> N >> K;
    vi a(N);
    cin >> a;
    ll mx = *max_element(ALL(a));
    RMQRUA::LST seg(mx + 1);
    REP(i, N) {
        seg.apply(a[i] - K, a[i] + K + 1, seg.query(a[i]) + 1);
    }
    cout << seg.query(0, mx + 1) << endl;
}

Measured memory_bytes: 13804