#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using S = long long;
using F = long long;
const S INF = 1e18;

S op(S a, S b) { return std::max(a, b); }
S e() { return -INF; }
S mapping(F f, S x) { return f + x; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }

ll max_a = 350000;

int main() {
    ll n, k;
    cin >> n >> k;
    lazy_segtree<S, op, e, F, mapping, composition, id> lst(max_a);
    for (ll i = 0;i < n;++i) {
        ll a;
        cin >> a;
        ll now = lst.get(a);
        lst.apply(max(0ll, a - k), min(max_a, a + k), max(1ll, now));
    }
    cout << lst.all_prod() + INF << endl;
}