#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

struct segmentTree{
    vector<int> node;
    int n;
    
    segmentTree(vector<int> v){
        int s = v.size();
        n = 2;
        while(n < s) n *= 2;
        node = vector<int>(2*n -1, inf);
        for(int i=0; i<s; i++){
            node[i +n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[2*i +1], node[2*i +2]);
        }
    }
    segmentTree(){}
    
    void Set(int val, int pos){
        int idx = n-1 + pos;
        node[idx] = val;
        do{
            idx = (idx -1)/2;
            node[idx] = min(node[2*idx +1], node[2*idx +2]);
        }while(idx != 0);
    }
    int pGet(int pos){
        return node[pos +n-1];
    }
    int Get(int l, int r){
        if(l == r) return inf;
        return _get(l, r, 0, 0, n);
    }
    int _get(int l, int r, int k, int cl, int cr){
        if(l <= cl && cr <= r){
            return node[k];
        }
        if(r <= cl || cr <= l){
            return inf;
        }
        int m = (cl +cr)/2;
        return min(_get(l, r, 2*k+1, cl, m), _get(l, r, 2*k+2, m, cr));
    }
};


int main(){
    int n;
    cin >> n;
    segmentTree segtree(vector<int>(n+1, 0));
    int coins = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(segtree.pGet(0) == 1){
            cout << "No" << endl;
            continue;
        }
        if(x >= n){
            cout << "Yes" << endl;
            segtree.Set(1, n);
            coins++;
            continue;
        }
        if(segtree.pGet(x) == 0){
            segtree.Set(1, x);
            cout << "Yes" << endl;
            coins++;
        }else{
            if(segtree.Get(1, x) == 0 || coins==x){
                coins++;
                for(int j=x; j>=0; j--){
                    if(segtree.pGet(j) == 0){
                        segtree.Set(1, j);
                        break;
                    }else{
                        segtree.Set(0, j);
                        coins--;
                    }
                }
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


### Prompt

Construct a Cpp code solution to the problem outlined:

Example

Input

6
2
3
1
1
4
2


Output

Yes
Yes
Yes
No
Yes
No

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

struct segmentTree{
    vector<int> node;
    int n;
    
    segmentTree(vector<int> v){
        int s = v.size();
        n = 2;
        while(n < s) n *= 2;
        node = vector<int>(2*n -1, inf);
        for(int i=0; i<s; i++){
            node[i +n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[2*i +1], node[2*i +2]);
        }
    }
    segmentTree(){}
    
    void Set(int val, int pos){
        int idx = n-1 + pos;
        node[idx] = val;
        do{
            idx = (idx -1)/2;
            node[idx] = min(node[2*idx +1], node[2*idx +2]);
        }while(idx != 0);
    }
    int pGet(int pos){
        return node[pos +n-1];
    }
    int Get(int l, int r){
        if(l == r) return inf;
        return _get(l, r, 0, 0, n);
    }
    int _get(int l, int r, int k, int cl, int cr){
        if(l <= cl && cr <= r){
            return node[k];
        }
        if(r <= cl || cr <= l){
            return inf;
        }
        int m = (cl +cr)/2;
        return min(_get(l, r, 2*k+1, cl, m), _get(l, r, 2*k+2, m, cr));
    }
};


int main(){
    int n;
    cin >> n;
    segmentTree segtree(vector<int>(n+1, 0));
    int coins = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(segtree.pGet(0) == 1){
            cout << "No" << endl;
            continue;
        }
        if(x >= n){
            cout << "Yes" << endl;
            segtree.Set(1, n);
            coins++;
            continue;
        }
        if(segtree.pGet(x) == 0){
            segtree.Set(1, x);
            cout << "Yes" << endl;
            coins++;
        }else{
            if(segtree.Get(1, x) == 0 || coins==x){
                coins++;
                for(int j=x; j>=0; j--){
                    if(segtree.pGet(j) == 0){
                        segtree.Set(1, j);
                        break;
                    }else{
                        segtree.Set(0, j);
                        coins--;
                    }
                }
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


```