description: Mr. Chanek gives you a sequence a indexed from 1 to n. Define f(a) as the number of indices where a_i = i. 
  
  You can pick an element from the current sequence and remove it, then concatenate the remaining elements together. For example, if you remove the 3-rd element from the sequence [4, 2, 3, 1], the resulting sequence will be [4, 2, 1]. 
  
  You want to remove some elements from a in order to maximize f(a), using zero or more operations. Find the largest possible f(a).
  
  Input
  
  The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the initial length of the sequence.
  
  The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 2 ⋅ 10^5) — the initial sequence a.
  
  Output
  
  Output an integer denoting the largest f(a) that can be obtained by doing zero or more operations.
  
  Examples
  
  Input
  
  
  7
  2 1 4 2 5 3 7
  
  
  Output
  
  
  3
  
  
  Input
  
  
  4
  4 2 3 1
  
  
  Output
  
  
  2
  
  Note
  
  In the first example, f(A) = 3 by doing the following operations.
  
  [2,1,4,2,5,3,7] → [2,1,2,5,3,7] → [1,2,5,3,7] → [1,2,5,3] → [1,2,3]
  
  In the second example, f(A) = 2 and no additional operation is needed.
solution: #include <bits/stdc++.h>
  using namespace std;
  template <class T>
  struct SegTree {
    int n;
    vector<T> t;
    T E = -1e9;
    T comb(T a, T b) { return max(a, b); }
    SegTree() {}
    SegTree(int _n) : n(_n) { t.assign(4 * n + 5, E); }
    SegTree(vector<T>& bld) : n(bld.size()) {
      t.assign(4 * n + 5, E);
      build(bld, 1, 0, n - 1);
    }
    void build(vector<T>& bld, int node, int tl, int tr) {
      if (tl == tr) {
        t[node] = bld[tl];
      } else {
        int tm = (tl + tr) / 2;
        build(bld, 2 * node, tl, tm);
        build(bld, 2 * node + 1, tm + 1, tr);
        pull(node);
      }
    }
    void pull(int node) { t[node] = comb(t[2 * node], t[2 * node + 1]); }
    T query(int l, int r) { return query(l, r, 1, 0, n - 1); }
    T query(int l, int r, int node, int tl, int tr) {
      if (r < tl || tr < l) return E;
      if (l <= tl && tr <= r) return t[node];
      int tm = (tl + tr) / 2;
      return comb(query(l, r, 2 * node, tl, tm),
                  query(l, r, 2 * node + 1, tm + 1, tr));
    }
    void update(int p, T val) { return update(p, val, 1, 0, n - 1); }
    void update(int p, T val, int node, int tl, int tr) {
      if (tl == tr) {
        t[node] = max(val, t[node]);
        return;
      }
      int tm = (tl + tr) / 2;
      if (p <= tm)
        update(p, val, 2 * node, tl, tm);
      else
        update(p, val, 2 * node + 1, tm + 1, tr);
      pull(node);
    }
  };
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    const int OFF = 2e5 + 7;
    const int MX = 2 * OFF;
    vector<int> a(n);
    vector<vector<int>> idxs(MX);
    SegTree<int> T(MX);
    T.update(OFF, 0);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      idxs[a[i]].push_back(i + 1);
    }
    int ans = 0;
    for (int val = 0; val < MX; val++) {
      auto& v = idxs[val];
      if (v.empty()) continue;
      reverse(v.begin(), v.end());
      for (auto& i : v) {
        int bst = T.query(OFF + val - i, MX - 1) + 1;
        T.update(OFF + val - i, bst);
        ans = max(ans, bst);
      }
    }
    cout << ans << '\n';
  }
  