func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mn = 1e5 + 1;   ll n, d, a[mn], b[mn], ans = 1, cnt = 1, pos = 1, ansid[mn];   struct pairs {     int val, id;     pairs operator+(pairs A) { return (pairs){val + A.val, id + A.id}; }   } tree[mn * 4], f[mn];   pairs maxp(pairs A, pairs B) {     if (A.val == B.val) {       if (A.id > B.id) return A;       return B;     }     if (A.val < B.val) return B;     return A;   }   void update(int l, int r, int id, int x, pairs p) {     if (l > x || x > r) return;     if (l == r) {       tree[id] = p;       return;     }     int mid = (l + r) / 2;     update(l, mid, id * 2, x, p);     update(mid + 1, r, id * 2 + 1, x, p);     tree[id] = maxp(tree[id * 2], tree[id * 2 + 1]);   }   pairs get(int l, int r, int id, int x, int y) {     if (l > y || x > r) return (pairs){0, 0};     if (x <= l && r <= y) return tree[id];     int mid = (l + r) / 2;     return maxp(get(l, mid, id * 2, x, y), get(mid + 1, r, id * 2 + 1, x, y));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; ++i) {       int u = upper_bound(b + 1, b + n + 1, a[i] - d) - b - 1;       int v = lower_bound(b + 1, b + n + 1, a[i] + d) - b;       int k = lower_bound(b + 1, b + n + 1, a[i]) - b;       if (u) f[i] = maxp(f[i], get(1, n, 1, 1, u) + (pairs){1, 0});       if (v <= n) f[i] = maxp(f[i], get(1, n, 1, v, n) + (pairs){1, 0});       f[i] = maxp(f[i], (pairs){1, i});       update(1, n, 1, k, (pairs){f[i].val, i});       if (ans < f[i].val) {         ans = f[i].val;         pos = i;       }     }     cout << ans <<   n ;     ansid[ans] = pos, cnt = ans - 1;     while (cnt) ansid[cnt--] = f[ansid[cnt + 1]].id;     for (int i = 1; i <= ans; ++i) cout << ansid[i] <<    ;     cout <<   n ;     return 0;   }   