#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++)
#define FORD(i, a, b) for(int i=(a), _b=(b); i>=_b; i--)
#define BIT(i, j) ((i>>j)&1)
#define pb push_back
#define ii pair<ll, ll>
#define pii pair<ll, ii>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const ll inf = 1e18;
const ll mod = 1e9+7;
const ll N = 200005;
const ll M = 50005;
int n;
ll x;
int len;
ll f[N], a[N], b[N];
void sub1 ()
{
    len = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > f[len])
        {
            f[++len] = a[i];
        }
        else
        {
            int vt = lower_bound(f, f + len + 1, a[i]) - f;
            f[vt] = a[i];
        }
    }
    cout << len;
}
void sub2 ()
{
    int ans = 0;
    for (int j = n; j >= 1; j--)
    {
        a[j] += x;
        len = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] > f[len])
            {
                f[++len] = a[i];
            }
            else
            {
                int vt = lower_bound(f, f + len + 1, a[i]) - f;
                f[vt] = a[i];
            }
        }
        ans = max(ans, len);
    }
    cout << ans;
}
vector <ll> pos;
int st1[4 * N], st2[4 * N], m;
void update (int i, int val, int st[], int l = 1, int r = m, int id = 1)
{
    if (i < l || i > r) return;
    if (l == r)
    {
        st[id] = val;
        return;
    }
    int mid = l + r >> 1;
    update (i, val, st, l, mid, id << 1);
    update (i, val, st, mid + 1, r, id << 1 | 1);
    st[id] = max(st[id << 1], st[id << 1 | 1]);
}
int get (int u, int v, int st[], int l = 1, int r = m, int id = 1)
{
    if (v < l || u > r) return 0;
    if (u <= l && r <= v) return st[id];
    int mid = l + r >> 1;
    return max(get(u, v, st, l, mid, id << 1), get(u, v, st, mid + 1, r, id << 1 | 1));
}
int pre[N];
void sub3 ()
{
    for (int i = 1; i <= n; i++)
    {
        b[i] = a[i] + x;
        pos.pb(a[i]);
        pos.pb(b[i]);
    }
    sort (all (pos));
    pos.erase(unique(all(pos)), pos.end());
    m = pos.size();
    for (int i = 1; i <= n; i++)
    {
        int x = lower_bound(all(pos), a[i]) - pos.begin() + 1;
        a[i] = x;
        x = lower_bound(all (pos), b[i]) - pos.begin() + 1;
        b[i] = x;
    }
    for (int i = n; i >= 1; i--)
    {
        int mx = get (b[i] + 1, m, st1);
        pre[i] = get(b[i], b[i], st1);
        update (b[i], mx + 1, st1);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int mx = get (1, a[i] - 1, st2);
        update (a[i], mx + 1, st2);
        update (b[i], pre[i], st1);
        ans = max(ans, mx + 1 + get (a[i] + 1, m, st1));
    }
    cout << ans;
}
void solve()
{
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (x == 0) sub1 ();
    else if (n <= 1000) sub2 ();
    else sub3 ();
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "bseq"
    if(fopen(task".inp", "r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    solve();
    return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |