#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

template<class T>
struct BIT{
	vector<T> dat;

	BIT(int sz) : dat(sz,0){}

	void add(int i,T x){
		for(;i < dat.size();i += i & -i) dat[i] += x;
	}

	T sum(T i){
		T ret = 0;
		for(;i;i -= i & -i) ret += dat[i];
		return ret;
	}
};

signed main(){
	int n;
	cin >> n;
	const int lim = 500010;
	BIT<int> bit(lim + 10);
	bool isCompleted = false,out = false;
	for(int i = 0;i < n;i++){
		int x;
		cin >> x;
		if(isCompleted){
			No();
			continue;
		}
		if(x >= lim){
			out = true;
			Yes();
			continue;
		}
		if(bit.sum(x) == x){
			if(bit.sum(lim) == x && !out){
				Yes();
				isCompleted = true;
			}else No();
		}else{
			Yes();
			bit.add(x,1);
			while(bit.sum(x) - bit.sum(x - 1) == 2){
				bit.add(x--,-2);
				bit.add(x,1);
			}
		}
	}
}

### Prompt

Please formulate a cpp solution to the following problem:

Example

Input

6
2
3
1
1
4
2


Output

Yes
Yes
Yes
No
Yes
No

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

template<class T>
struct BIT{
	vector<T> dat;

	BIT(int sz) : dat(sz,0){}

	void add(int i,T x){
		for(;i < dat.size();i += i & -i) dat[i] += x;
	}

	T sum(T i){
		T ret = 0;
		for(;i;i -= i & -i) ret += dat[i];
		return ret;
	}
};

signed main(){
	int n;
	cin >> n;
	const int lim = 500010;
	BIT<int> bit(lim + 10);
	bool isCompleted = false,out = false;
	for(int i = 0;i < n;i++){
		int x;
		cin >> x;
		if(isCompleted){
			No();
			continue;
		}
		if(x >= lim){
			out = true;
			Yes();
			continue;
		}
		if(bit.sum(x) == x){
			if(bit.sum(lim) == x && !out){
				Yes();
				isCompleted = true;
			}else No();
		}else{
			Yes();
			bit.add(x,1);
			while(bit.sum(x) - bit.sum(x - 1) == 2){
				bit.add(x--,-2);
				bit.add(x,1);
			}
		}
	}
}

```