#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+5];

	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	set<int> s;
	set<int>::iterator it,it2;
	cout<<1<<" ";
	int count2,h=1;
	int flag=0,count=0;
	s.insert(n);
	s.insert(-1);
	int p=0;
	int lo=n;
	int count3;
	for(int i=0;i<n;i++){
		if(flag==0){
			if(a[i]==n){
				s.insert(a[i]);
				it=s.find(n);
				count3=1;
				while(1){

					--it;
					if(*it==-1)break;
					if(*it==a[i]-count3){
					count3++;
//					cout<<"p"<<p<<endl;
					lo=*it;
					p--;

					}
					else break;

				}
				count+=count3;
				//count+=count3;
	//			cout<<count<<endl;
				cout<<i+2-count<<" ";
				flag=1;
			}
			else{
			s.insert(a[i]);
			cout<<i+2<<" ";
			}
		}

		else{
			s.insert(a[i]);
			it=s.find(a[i]);
			it2=it;
			++it2;
			if(*it2==lo){
	//			cout<<"hi"<<" "<<a[i]<<" "<<lo<<endl;
				count2=1;
				lo=*it;
				while (1){
					--it;
				//	--it;
				//	cout<<*it<<endl;
					if(*it==-1)break;
				//cout<<"hi"<<a[i]-count2<<endl;
					if(*it==a[i]-count2)
					{
						count2++;
		//				cout<<count2<<endl;
						p--;
						lo=*it;
					}
					else break;
				}
			count+=count2;
	//			cout<<count2<<endl;
				cout<<i+2-count<<" ";
			}
			else{
				cout<<i+2-count<<" ";
			}
		}

	/*	if(a[i]==n){
			flag=1;
			//it=s.find(n)
			//for (it2=it
			cout<<i-count+1<<" ";
			h=h-count;
			count++;

		}
		else{
		s.insert(a[i]);
		set<int>::iterator k;
		k=s.find(a[i]);
		++k;

		if(*k==p and *k==a[i]+1 and flag==1){
			count++;
			p--;
		*if(*s.begin()==a[i]+1 and s.size()==n-a[i])cout<<i-count+1<<" ";}
		//else if(*k==p and *k==a[i]+1 and flag==0){count++;p--;}
		else {
			if(flag==1)
			{		cout<<i+2-count<<" ";h+=1;}
			else cout<<i+2<<" ";
		}
		if(*k==p and *k==a[i]+1 and flag==0){count++;p--;}
		}*/
//		cout<<"hi"<<*s.begin()<<endl;
	//	if(a[i]==n){s.insert(a[i]);
		 /*if(*s.begin()==a[i]+1 and flag==1){cout<<1<<" ";s.insert(a[i]);}
		else if(flag==0 and *s.begin()==a[i]+1){cout<<i+1+1<<" ";s.insert(a[i]);}
		 else {
			if(a[i]==n){flag=1;cout<<2<<" ";}
			else {cout<<i+1+1<<" ";}//s.insert(a[i]);}
		}*/
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+5];

	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	set<int> s;
	set<int>::iterator it,it2;
	cout<<1<<" ";
	int count2,h=1;
	int flag=0,count=0;
	s.insert(n);
	s.insert(-1);
	int p=0;
	int lo=n;
	int count3;
	for(int i=0;i<n-1;i++){
		if(flag==0){
			if(a[i]==n){
				s.insert(a[i]);
				it=s.find(n);
				count3=1;
				while(1){

					--it;
					if(*it==-1)break;
					if(*it==a[i]-count3){
					count3++;
//					cout<<"p"<<p<<endl;
					lo=*it;
					p--;

					}
					else break;

				}
				count+=count3;
				//count+=count3;
	//			cout<<count<<endl;
				cout<<i+2-count<<" ";
				flag=1;
			}
			else{
			s.insert(a[i]);
			cout<<i+2<<" ";
			}
		}

		else{
			s.insert(a[i]);
			it=s.find(a[i]);
			it2=it;
			++it2;
			if(*it2==lo){
	//			cout<<"hi"<<" "<<a[i]<<" "<<lo<<endl;
				count2=1;
				while (1){
					--it;
				//	--it;
				//	cout<<*it<<endl;
					if(*it==-1)break;
				//cout<<"hi"<<a[i]-count2<<endl;
					if(*it==a[i]-count2)
					{
						count2++;
		//				cout<<count2<<endl;
						p--;
						lo=*it;
					}
					else break;
				}
			count+=count2;
	//			cout<<count2<<endl;
				cout<<i+2-count<<" ";
			}
			else{
				cout<<i+2-count<<" ";
			}
		}

	/*	if(a[i]==n){
			flag=1;
			//it=s.find(n)
			//for (it2=it
			cout<<i-count+1<<" ";
			h=h-count;
			count++;

		}
		else{
		s.insert(a[i]);
		set<int>::iterator k;
		k=s.find(a[i]);
		++k;

		if(*k==p and *k==a[i]+1 and flag==1){
			count++;
			p--;
		*if(*s.begin()==a[i]+1 and s.size()==n-a[i])cout<<i-count+1<<" ";}
		//else if(*k==p and *k==a[i]+1 and flag==0){count++;p--;}
		else {
			if(flag==1)
			{		cout<<i+2-count<<" ";h+=1;}
			else cout<<i+2<<" ";
		}
		if(*k==p and *k==a[i]+1 and flag==0){count++;p--;}
		}*/
//		cout<<"hi"<<*s.begin()<<endl;
	//	if(a[i]==n){s.insert(a[i]);
		 /*if(*s.begin()==a[i]+1 and flag==1){cout<<1<<" ";s.insert(a[i]);}
		else if(flag==0 and *s.begin()==a[i]+1){cout<<i+1+1<<" ";s.insert(a[i]);}
		 else {
			if(a[i]==n){flag=1;cout<<2<<" ";}
			else {cout<<i+1+1<<" ";}//s.insert(a[i]);}
		}*/
	}
	cout<<1<<endl;
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    int m, p;
    scanf("%d", &m);
    vector<int> coins(m, 0);

    int j = m-1;
    printf("1");
    rep(m-1){
      int ans = 0;
      scanf("%d", &p);
      coins[p-1] = 1;
      while(coins[j] == 1 && j > 0) j--;
      reppp(k, 0, j){
        if(coins[k] == 1) ans++;
      }
      printf(" %d", ans+1);
    }
    printf(" 1");
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300001-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int m;
    cin >> m;
    n = 1;
    while(n < m) n *= 2;
    init(n);
    vector<int> p(m);
    rep(m){
        cin >> p[i];
        p[i]--;
    }

    vector<int> ans(m+2, 1), coins(m);

    rep(m-1){
        update(p[i], 1);
        coins[p[i]] = 1;
        int end = n-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        int count = query(0, end+1, 0, 0, n) + 1;
        ans[i+1] = count;
    }

    printf("%d", ans[0]);
    reppp(i, 1, n){
        printf(" %d", ans[i]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300001-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    int m, p;
    scanf("%d", &m);
    init(m);

    vector<int> coins(m);

    printf("1");
    rep(m-1){
        scanf("%d", &p);
        p--;
        update(p, 1);
        coins[p] = 1;
        int end = m-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        printf(" %d", query(0, end+1, 0, 0, n) + 1);
    }
    printf(" 1");
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300001-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int m;
    scanf("%d", &m);
    init(m);
    vector<int> p(m);
    rep(m){
        scanf("%d", &p[i]);
        p[i]--;
    }

    vector<int> ans(m+2, 1), coins(m);

    rep(m-1){
        update(p[i], 1);
        coins[p[i]] = 1;
        int end = m-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        int count = query(0, end+1, 0, 0, n) + 1;
        ans[i+1] = count;
    }

    printf("%d", ans[0]);
    reppp(i, 1, m){
        printf(" %d", ans[i]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300005];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    int m, p;
    scanf("%d", &m);
    init(m);

    vector<int> coins(m);

    printf("1");
    rep(m-1){
        scanf("%d", &p);
        p--;
        update(p, 1);
        coins[p] = 1;
        int end = m-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        printf(" %d", query(0, end+1, 0, 0, n) + 1);
    }
    printf(" 1");
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300001-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int m;
    cin >> m;
    init(m);
    vector<int> p(m);
    rep(m){
        cin >> p[i];
        p[i]--;
    }

    vector<int> ans(m+2, 1), coins(m);

    rep(m-1){
        update(p[i], 1);
        coins[p[i]] = 1;
        int end = m-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        int count = query(0, end+1, 0, 0, n) + 1;
        ans[i+1] = count;
    }

    printf("%d", ans[0]);
    reppp(i, 1, m){
        printf(" %d", ans[i]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n, seg[2*300001-1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  rep(2*n-1) seg[i] = 0;
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int m;
    cin >> m;
    init(m);
    vector<int> p(m);
    rep(m){
        cin >> p[i];
        p[i]--;
    }

    vector<int> ans(m+2, 1), coins(m);

    rep(m-1){
        update(p[i], 1);
        coins[p[i]] = 1;
        int end = n-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        int count = query(0, end+1, 0, 0, n) + 1;
        ans[i+1] = count;
    }

    printf("%d", ans[0]);
    reppp(i, 1, n){
        printf(" %d", ans[i]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

int n;
vector<int> seg(2*400000, 0);
void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  //n: number of leaf
  /*
  rep(2*n-1){
      seg[i] = 0;
  }
  */
}

void update(int k, int a){
  k += n-1;
  seg[k] = a;
  while(k > 0){
	k = (k-1) / 2;
	seg[k] = seg[2*k+1] + seg[2*k+2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query(a, b, k*2+1, l, (l+r) / 2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
  return vl + vr;
}

signed main(){
    int m, p;
    scanf("%d", &m);
    init(m);
    vector<int> coins(m);

    printf("1");
    rep(m-1){
        scanf("%d", &p);
        p--;
        update(p, 1);
        coins[p] = 1;
        int end = m-1;
        while(end >= 0 && coins[end] == 1) end--;
        /*
        printf("end:%d\n", end);
        repp(j, m){
            cout << query(0, j+1, 0, 0, n);
        }
        cout << endl;
        */
        printf(" %d", query(0, end+1, 0, 0, n) + 1);
    }
    printf(" 1");
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> p(n);
    rep(n){
        cin >> p[i];
        p[i]--;
    }

    vector<int> coins(n, 0), ans(n+1, 1);

    rep(n-1){
        coins[p[i]] = 1;
        vector<int> coins_copy(coins);
        int start = 0, end = n;
        while(true){
            while(start < n && coins_copy[start] == 0) start++;
            while(end-1 >= 0 && coins_copy[end-1] == 1) end--;
            // printf("start:%d end:%d\n", start, end);
            if(start == end) break;
            reppp(k, start, end-1){
                if(k < n-1 && coins_copy[k] == 1 && coins_copy[k+1] == 0){
                    swap(coins_copy[k], coins_copy[k+1]);
                    // printf("%d, %d\n", k, k+1);
                }
            }
            ans[i+1]++;
        }
    }

    printf("%d", ans[0]);
    reppp(i, 1, n){
        printf(" %d", ans[i]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>

using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    int m, p;
    scanf("%d", &m);
    vector<int> coins(m, 0);

    int j = m-1, cnt = 0;
    printf("1");
    rep(m-1){
      scanf("%d", &p);
      coins[p-1] = 1;
      cnt++;
      while(coins[j] == 1 && j > 0){
        cnt--;
        j--;
      }
      printf(" %d", cnt+1);
    }
    printf(" 1");
}


#include<bits/stdc++.h>
using namespace std;
// this is not good :/
// why you do this ? :D
int main(){
	int n ;
	scanf("%d" , &n);
	vector< int > Roundtable(n);
	int behind = n;
	int noLimit = 0;
	cout << "1 ";
	for(int i = 0 ;i < n ;i ++){
		int frontEndToInf;
		scanf("%d" , &frontEndToInf);
		if(i)cout << " " ;
		Roundtable[frontEndToInf] = 1;
		while(behind > noLimit &&  Roundtable[behind])behind --;
		cout << (i + 2 - (n - behind)) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// you are not the catWoman are you :D ? :V
int main(){
	int n ;
	scanf("%d" , &n);
	vector< bool > r(n);
	int x = n;
	cout << "1";
	for(int i = 0 ;i < n ;i ++){
		int xx;scanf("%d" , &xx);
		r[xx] = 1;
		while(r[x])x --;
		cout << " " << (i + 2 - (n - x) ) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// goodnight guys :D :V
// happy long problems :D
// you can't see me :V :D :D
int main(){
	int horses , magicHero = 2;
	scanf("%d" , &horses);
	vector< bool > Roundtable(horses + 1);
	int behindForward = horses;
	cout << "1";
	for(int anyTime = 0 ;anyTime < horses ;anyTime ++){
		int waqe7;scanf("%d" , &waqe7);
		Roundtable[waqe7] = 1;
		while(Roundtable[behindForward])behindForward --;
		cout << " " << (anyTime + magicHero - (horses - behindForward) ) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n ;
	scanf("%d" , &n);
	vector< int > Roundtable(n);
	int behind = n;
	int noLimit = 0;
	cout << 1 << " " ;
	for(int i = 0 ;i < n ;i ++){
		int frontEndToInf;
		scanf("%d" , &frontEndToInf);
		Roundtable[frontEndToInf] = 1;
		while(behind > noLimit &&  Roundtable[behind])behind --;
		cout << (i + 2 - (n - behind)) << " " ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// wow my frinds ..  :V :V :V
int main(){
	int n ;
	scanf("%d" , &n);
	vector< int > Roundtable(n);
	int behind = n;
	cout << 1 << " " ;
	for(int i = 0 ;i < n ;i ++){
		int frontEndToInf;
		scanf("%d" , &frontEndToInf);
		Roundtable[frontEndToInf] = 1;
		while(Roundtable[behind])behind --;
		cout << i + 2 - (n - behind) << " " ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// goodnight guys :D :V
// happy long problems :D
// you can't see me :V :D :D
int main(){
	int horses ;
	scanf("%d" , &horses);
	vector< bool > Roundtable(horses);
	int behindForward = horses;
	cout << "1";
	for(int anyTime = 0 ;anyTime < horses ;anyTime ++){
		int waqe7;scanf("%d" , &waqe7);
		Roundtable[waqe7] = 1;
		while(Roundtable[behindForward])behindForward --;
		cout << " " << (anyTime + 2 - (horses - behindForward) ) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// you cant see me :D :D
int main(){
	int n ;
	cin >> n;
	vector< bool > r(n);
	int x = n;
	cout << "1";
	for(int i = 0 ;i < n ;i ++){
		int xx;cin >> xx;
		r[xx] = 1;
		while(r[x])x --;
		cout << " " << (i + 2 - (n - x) ) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// goodnight guys :D :V
// happy long problems :D
// you can't see me :V :D :D

int main(){
	int n ;
	scanf("%d" , &n);
	vector< bool > r(n);
	int x = n;
	cout << "1";
	for(int i = 0 ;i < n ;i ++){
		int xx;scanf("%d" , &xx);
		r[xx] = 1;
		while(r[x])x --;
		cout << " " << (i + 2 - (n - x) ) ;
	}
	cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
// goodnight guys :D :V
// happy long problems :D
// you can't see me :V :D :D
int main(){
	int horses , heroSummon = 2 , summonHero = 1 ;
	scanf("%d" , &horses);
	vector< bool > Roundtable(horses + summonHero);
	int behindForward = horses;
	cout << "1";
	for(int anyTime = 0 ;anyTime < horses ;anyTime ++){
		int waqe7;scanf("%d" , &waqe7);
		Roundtable[waqe7] = 1;
		while(Roundtable[behindForward])behindForward --;
		cout << " " << (anyTime + heroSummon - (horses - behindForward) ) ;
	}
	cout << endl;

}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;

	vector<bool> I(N+1, 0);
	int res = 1;
	int last = N;
	printf("1 ");
	for(int i = 0; i < N; ++i)
	{
		int curr;
		scanf("%d", &curr);

		res++;
		I[curr] = 1;
		while(I[last] == 1)
		{
			res--;
			last--;
		}
		printf("%d ", res);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;

	vector<bool> I(N+1, false);
	int res = 1;
	int last = N;
	cout << "1 ";
	for(int i = 0; i < N; ++i)
	{
		int curr;
		cin >> curr;

		res++;
		I[curr] = 1;
		if(I[last] == 1)
		{
			while(I[last] == 1)
			{
				res--;
				last--;
			}
		}
		cout << res << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;

	vector<bool> I(N+1, 0);
	int res = 1;
	int last = N;
	printf("1 ");
	for(int i = 0; i < N; ++i)
	{
		int curr;
		scanf("%d", &curr);

		res++;
		I[curr] = 1;
		while(last >= 0 && I[last] == 1)
		{
			res--;
			last--;
		}
		printf("%d ", res);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin >> N;

	vector<bool> I(N+1, false);
	int res = 1;
	int last = N;
	cout << "1 ";
	for(int i = 0; i < N; ++i)
	{
		int curr;
		cin >> curr;

		res++;
		I[curr] = 1;
		if(I[last] == 1)
		{
			while(I[last] == 1)
			{
				res--;
				last--;
			}
		}
		cout << res << ' ';
	}

	return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int i,n,store=0;
    cin>>n;
    int count[n+1],arr[n],temp=n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        count[i+1]=0;
    }
    cout<<"1 ";
    for(i=0;i<n;i++)
    {
        count[arr[i]]++;
        while(count[temp]==1)
        {
            store++;
            temp--;
        }
        cout<<(i+2-store)<<" ";
    }
    cout<<endl;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int i,n,store=0;
    cin>>n;
    int count[n+1],arr[n],temp=n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        count[i+1]=0;
    }
    cout<<"1";
    for(i=0;i<n;i++)
    {
        count[arr[i]]++;
        while(count[temp]==1)
        {
            store++;
            temp--;
        }
        cout<<" "<<(i+2-store);
    }
    cout<<endl;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int i,n,store=0;
    cin>>n;
    int count[3000001],arr[3000001],temp=n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        count[i+1]=0;
    }
    cout<<"1";
    for(i=0;i<n;i++)
    {
        count[arr[i]]++;
        while(count[temp]==1)
        {
            store++;
            temp--;
        }
        cout<<" "<<(i+2-store);
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2e9;

bool a[maxn];

int main()
{
	IOS;
	int n;
	cin>>n;

	cout<<1;
	int cur=0;
	REP(i,n){
		int x;
		cin>>x;
		a[x-1]=1;
		while(cur<n&&a[n-1-cur]==1){
			cur++;
		}

		cout<<' '<<2+i-cur;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2e9;

bool a[maxn];

int main()
{
	int n;
	cin>>n;

	cout<<1;
	int cur=0;
	REP(i,n){
		int x;
		cin>>x;
		a[x-1]=1;
		while(cur<n&&a[n-1-cur]==1){
			cur++;
		}

		cout<<' '<<2+i-cur;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2e9;

bool a[maxn];

int main()
{
	int n;
	cin>>n;

	cout<<1;
	int cur=0;
	REP(i,n){
		int x;
		cin>>x;
		a[x-1]=1;
		while(a[n-1-cur]==1){
			cur++;
		}

		cout<<' '<<2+i-cur;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[1200000];
stack<int> s;
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build((node<<1)+1, start, mid);
        // Recurse on the right child
        build((node<<1)+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[(node<<1)+1] + tree[(node<<1)+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1((node<<1)+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1((node<<1)+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[(node<<1)+1] + tree[(node<<1)+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query((node<<1)+1, start, mid, l, r);
    int p2 = query((node<<1)+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    build(0,0,n-1);
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    //cout<<s.top()<<endl;
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        printf("%d ",query(0,0,n-1,0,s.top())+1);
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
#define N 300001
int a[N];
int BIT[600000];
int n;
stack<int> s;
void update(int x, int delta)
{
    while(x<=n)
    {
        BIT[x] += delta;
        x = x + (x & (-x));
        //cout<<x<<endl;
    }
}
int query(int x)
{
     int ans = 0;
    while(x != 0)
    {
        ans += BIT[x];
        x = x&(x-1);
    }
    return ans;
}
int  main()
{
    scanf("%d",&n);
    for(int i=0;i<600000;i++)
        BIT[i]=0;
    for(int i=0;i<n;i++)
    {
        s.push(i+1);
    }
    bool top1[n+1];
    for(int i=0;i<=n;i++)
    {
        top1[i]=false;
    }
    top1[0]=true;
    printf("1 ");
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            printf("1\n");
            break;
        }
        update(a[i],1);
        /*for(int i=0;i<=4;i++)
        {
            cout<<BIT[i]<<" ";
        }
        cout<<endl;*/
        printf("%d ",query(s.top())+1);
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[1200000];
stack<int> s;
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node+1, start, mid);
        // Recurse on the right child
        build(2*node+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1(2*node+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1(2*node+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node+1, start, mid, l, r);
    int p2 = query(2*node+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    build(0,0,n-1);
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    //cout<<s.top()<<endl;
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        printf("%d ",query(0,0,n-1,0,s.top())+1);
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[1200000];
stack<int> s;
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node+1, start, mid);
        // Recurse on the right child
        build(2*node+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1(2*node+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1(2*node+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node+1, start, mid, l, r);
    int p2 = query(2*node+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    int n;
    cin>>n;
    int a[n];
    build(0,0,n-1);
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    //cout<<s.top()<<endl;
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        cout<<query(0,0,n-1,0,s.top())+1<<" ";
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
#define N 300001
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    cout<<1<<" ";
    int r=n-1;
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    int y=0;
    for(int i=0;i<n;i++)
    {
        top1[a[i]]=true;
        while(r>=0)
        {
            if(top1[r])
            {
                r--;
                y++;
            }
            else
            {
                break;
            }
        }
        cout<<i-y+2<<" ";
       /* if(i==7)
        {
            cout<<endl;
            cout<<r<<" "<<y<<endl;
        }*/
    }
    cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
#define N 300001
int a[N];
int BIT[600000];
int n;
stack<int> s;
void update(int x, int delta)
{
    while(x< n)
    {
        BIT[x] += delta;
        x = x + (x & (-x));
        //cout<<x<<endl;
    }
}
int query(int x)
{
     int ans = 0;
    while(x != 0)
    {
        ans += BIT[x];
        x = x&(x-1);
    }
    return ans;
}
int  main()
{
    scanf("%d",&n);
    for(int i=0;i<600000;i++)
        BIT[i]=0;
    for(int i=0;i<n;i++)
    {
        s.push(i+1);
    }
    //cout<<s.top()<<endl;
    bool top1[n+1];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update(a[i],1);
        //cout<<a[i]+1<<endl;
        printf("%d ",query(s.top())+1);
        //break;
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[100000];
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node+1, start, mid);
        // Recurse on the right child
        build(2*node+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1(2*node+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1(2*node+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node+1, start, mid, l, r);
    int p2 = query(2*node+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    long n;
    cin>>n;
    int a[n];
    build(0,0,n-1);
    stack<int> s;
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        cout<<query(0,0,n-1,0,s.top())+1<<" ";
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[700000];
stack<int> s;
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node+1, start, mid);
        // Recurse on the right child
        build(2*node+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1(2*node+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1(2*node+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node+1, start, mid, l, r);
    int p2 = query(2*node+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    int n;
    cin>>n;
    int a[n];
    build(0,0,n-1);
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        cout<<query(0,0,n-1,0,s.top())+1<<" ";
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
int tree[700000];
void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        tree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node+1, start, mid);
        // Recurse on the right child
        build(2*node+2, mid+1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
void update1(int node, int start, int end, int idx, int val)
{
    //cout<<start<<" "<<end<<" "<<idx<<endl;
    if(start == end)
    {
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update1(2*node+1, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update1(2*node+2, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2*node+1] + tree[2*node+2];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node+1, start, mid, l, r);
    int p2 = query(2*node+2, mid+1, end, l, r);
    return (p1 + p2);
}
int  main()
{
    long n;
    cin>>n;
    int a[n];
    build(0,0,n-1);
    stack<int> s;
    for(int i=0;i<n;i++)
    {
        s.push(i);
    }
    bool top1[n];
    for(int i=0;i<n;i++)
    {
        top1[i]=false;
    }
    cout<<1<<" ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update1(0,0,n-1,a[i],1);
        cout<<query(0,0,n-1,0,s.top())+1<<" ";
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define s(n) scanf("%ld",&n)
#define p(n) prlongf("%ld\n",n)*/
#define N 300001
int a[N];
int BIT[600000];
int n;
stack<int> s;
void update(int x, int delta)
{
    while(x<=n)
    {
        BIT[x] += delta;
        x = x + (x & (-x));
        //cout<<x<<endl;
    }
}
int query(int x)
{
     int ans = 0;
    while(x != 0)
    {
        ans += BIT[x];
        x = x&(x-1);
    }
    return ans;
}
int  main()
{
    scanf("%d",&n);
    for(int i=0;i<600000;i++)
        BIT[i]=0;
    for(int i=0;i<n;i++)
    {
        s.push(i+1);
    }
    bool top1[n+1];
    for(int i=0;i<=n;i++)
    {
        top1[i]=false;
    }
    top1[0]=true;
    cout<<1<<" ";
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        //cout<<a[i]<<endl;
        top1[a[i]]=true;
        while(!s.empty())
        {
            if(top1[s.top()])
                s.pop();
            else
                break;
        }
        if(s.empty())
        {
            cout<<1<<endl;
            break;
        }
        update(a[i],1);
        /*for(int i=0;i<=4;i++)
        {
            cout<<BIT[i]<<" ";
        }
        cout<<endl;*/
        printf("%d ",query(s.top())+1);
    }
    cout<<endl;
return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
map<char,int>mp;
set<int>st;
const int N=3e5+100;
int vis[N];
int main()
{
    int n,a=0;
    cin>>n;
    memset(vis,0,sizeof vis);
    for(int i=0;i<=n;i++)
    {
        if(i!=0)
        cin>>a;
        vis[a]=1;
        int cnt=0;
        for(int j=n;j>0;j--)
        {
            if(vis[j]==1)
                cnt++;
            else break;
        }
        if(i!=n)
            cout<<i-cnt+1<<" ";
        else
            cout<<i-cnt+1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
map<char,int>mp;
set<int>st;
const int N=3e5+100;
int vis[N];
int main()
{
    int n,a=0;
    cin>>n;
    memset(vis,0,sizeof vis);
    int ed=n;
    int ans=1;
    cout<<1<<' ';
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        vis[a]=1;
        if(a==ed)
        {
            ed--;
            while(vis[ed]==1)
            {
                ed--;
                ans--;
            }
        }
        else
            ans++;
        if(i!=n)
            cout<<ans<<' ';
        else
            cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
map<char,int>mp;
set<int>st;
const int N=3e5+100;
int vis[N];
int main()
{
    ios::sync_with_stdio(false  );
    int n,a=0;
    cin>>n;
    memset(vis,0,sizeof vis);
    int ed=n;
    int ans=1;
    cout<<1;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        vis[a]=1;
        if(a==ed)
        {
            while(vis[--ed])
                ans--;
        }
        else
            ans++;
        cout<<' '<<ans;

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
map<char,int>mp;
set<int>st;
const int N=3e5+100;
int vis[N];
int main()
{
    int n,a=0;
    cin>>n;
    memset(vis,0,sizeof vis);
    int ed=n;
    int ans=1;
    cout<<1;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        vis[a]=1;
        if(a==ed)
        {
            while(vis[--ed])
                ans--;
        }
        else
            ans++;
        cout<<' '<<ans;

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
map<char,int>mp;
set<int>st;
const int N=3e5+100;
int vis[N];
int main()
{
    int n,a=0;
    cin>>n;
    memset(vis,0,sizeof vis);
    int ed=n;
    int ans=1;
    cout<<1<<' ';
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        vis[a]=1;
        if(a==ed)
        {
            while(vis[--ed]==1)
                ans--;
        }
        else
            ans++;
        if(i!=n)
            cout<<ans<<' ';
        else
            cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
//queue<int> qu;

//typedef pair<int,int> P;

class node{
	public:
		int number,left_,right_;//,ans_;
};

node tree_[1200005];
int ans[300005];
//int k=0;

void build_(int l,int r,int num){
	tree_[num].number=r-l+1;
	tree_[num].left_=l;
	tree_[num].right_=r;
//	tree_[num].ans_=0;
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build_(l,mid,num<<1);
	build_(mid+1,r,num<<1|1);
}

void inline  insert_(int x,int num){
	if(tree_[num].left_==tree_[num].right_){
		tree_[num].number--;
		return;
	}
	int mid=(tree_[num].right_+tree_[num].left_)>>1;
	if(x<=mid)
		insert_(x,num<<1);
	else
		insert_(x,num<<1|1);
	tree_[num].number=tree_[num<<1].number+tree_[num<<1|1].number;
}

int get_num(int num){
	int number=0;
	if(tree_[num].left_==tree_[num].right_)
		return 0;
	if(tree_[num].number<(tree_[num].right_-tree_[num].left_+1)){
		if(tree_[num<<1|1].number>0)
			number+=(tree_[num<<1].right_-tree_[num<<1].left_+1)-tree_[num<<1].number;
		else
			number+=get_num(num<<1);
		number+=get_num(num<<1|1);
	}
	return number;
}

int main(){
	int n,x;
	scanf("%d",&n);
	build_(1,n,1);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		insert_(x,1);
		if(i==n-1)
			break;
		ans[i]=get_num(1)+1;
	}
	printf("1");
	for(int i=0;i<n-1;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
//queue<int> qu;

//typedef pair<int,int> P;

class node{
	public:
		int number,left_,right_;//,ans_;
};

node tree_[1200005];
int ans[300005];
//int k=0;

void build_(int l,int r,int num){
	tree_[num].number=r-l+1;
	tree_[num].left_=l;
	tree_[num].right_=r;
//	tree_[num].ans_=0;
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build_(l,mid,num<<1);
	build_(mid+1,r,num<<1|1);
}

void inline  insert_(int x,int num){
	if(tree_[num].left_==tree_[num].right_){
		tree_[num].number--;
		return;
	}
	int mid=(tree_[num].right_+tree_[num].left_)>>1;
	if(x<=mid)
		insert_(x,num<<1);
	else
		insert_(x,num<<1|1);
	tree_[num].number=tree_[num<<1].number+tree_[num<<1|1].number;
}

int get_num(int num){
	int number=0;
	if(tree_[num].left_==tree_[num].right_)
		return 0;
	if(tree_[num].number<(tree_[num].right_-tree_[num].left_+1)){
		if(tree_[num<<1|1].number>0)
			number+=(tree_[num<<1].right_-tree_[num<<1].left_+1)-tree_[num<<1].number+get_num(num<<1|1);
		else
			number+=get_num(num<<1);
	}
	return number;
}

int main(){
	int n,x;
	scanf("%d",&n);
	build_(1,n,1);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		insert_(x,1);
		if(i==n-1)
			break;
		ans[i]=get_num(1)+1;
	}
	printf("1");
	for(int i=0;i<n-1;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
queue<int> qu;

typedef pair<int,int> P;

class node{
	public:
		int number,left_,right_;//,ans_;
};

node tree_[300005];
int ans[300005];
int k=0;

void build_(int l,int r,int num){
	tree_[num].number=r-l+1;
	tree_[num].left_=l;
	tree_[num].right_=r;
//	tree_[num].ans_=0;
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build_(l,mid,num<<1);
	build_(mid+1,r,num<<1|1);
}

void insert_(int x,int num){
	if(tree_[num].left_==tree_[num].right_){
		tree_[num].number--;
		return;
	}
	int mid=(tree_[num].right_+tree_[num].left_)>>1;
	if(x<=mid)
		insert_(x,num<<1);
	else
		insert_(x,num<<1|1);
	tree_[num].number=tree_[num<<1].number+tree_[num<<1|1].number;
}

int get_num(int num){
	int number=0;
	if(tree_[num].left_==tree_[num].right_)
		return 0;
	if(tree_[num].number<(tree_[num].right_-tree_[num].left_+1)){
		if(tree_[num<<1|1].number>0)
			number+=(tree_[num<<1].right_-tree_[num<<1].left_+1)-tree_[num<<1].number;
		else
			number+=get_num(num<<1);
		number+=get_num(num<<1|1);
	}
	return number;
}

int main(){
	int n,x;
	scanf("%d",&n);
	build_(1,n,1);
	int num=1;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		insert_(x,1);
		if(i==n-1)break;
		ans[k++]=get_num(1)+1;
	}
	printf("1");
	for(int i=0;i<k;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
#define LL long long
const LL maxn = 300000+10;
LL n,p[maxn],sum,vis[maxn],last;
int main()
{
    scanf("%lld",&n);
    for(int i=0;i<n;i++) scanf("%lld",&p[i]);
    last = n;sum = 0;
    printf("1");
    for(int i=0;i<n;i++){
        vis[p[i]]=1; sum++;
        while(vis[last]) sum --,last--;
        printf(" %lld",sum+1);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
queue<int> qu;

typedef pair<int,int> P;

class node{
	public:
		int number,left_,right_;//,ans_;
};

node tree_[1200005];
int ans[300005];
int k=0;

void build_(int l,int r,int num){
	tree_[num].number=r-l+1;
	tree_[num].left_=l;
	tree_[num].right_=r;
//	tree_[num].ans_=0;
	if(l==r)
		return;
	int mid=(l+r)>>1;
	build_(l,mid,num<<1);
	build_(mid+1,r,num<<1|1);
}

void insert_(int x,int num){
	if(tree_[num].left_==tree_[num].right_){
		tree_[num].number--;
		return;
	}
	int mid=(tree_[num].right_+tree_[num].left_)>>1;
	if(x<=mid)
		insert_(x,num<<1);
	else
		insert_(x,num<<1|1);
	tree_[num].number=tree_[num<<1].number+tree_[num<<1|1].number;
}

int get_num(int num){
	int number=0;
	if(tree_[num].left_==tree_[num].right_)
		return 0;
	if(tree_[num].number<(tree_[num].right_-tree_[num].left_+1)){
		if(tree_[num<<1|1].number>0)
			number+=(tree_[num<<1].right_-tree_[num<<1].left_+1)-tree_[num<<1].number;
		else
			number+=get_num(num<<1);
		number+=get_num(num<<1|1);
	}
	return number;
}

int main(){
	int n,x;
	scanf("%d",&n);
	build_(1,n,1);
	int num=1;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		insert_(x,1);
		if(i==n-1)break;
		ans[k++]=get_num(1)+1;
	}
	printf("1");
	for(int i=0;i<k;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
queue<int> qu;

typedef pair<int,int> P;

//int a[300005];
int ball[300005];
int ans[300005];
int  k=0;

void search_(int n){
	int num=0,number=0;
	for(int i=1;i<=n;i++){
		if(ball[i]==1)
			num++;
		else if(ball[i]==0){
			number+=num;
			num=0;
		}
	}
	ans[k++]=number+1;
}

int main(){
	int n,x;
	scanf("%d",&n);
	memset(ball,0,sizeof(ball));
	int num=1;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(i==n-1)
			break;
		ball[x]=1;
		search_(n);
	}
	printf("1");
	for(int i=0;i<k;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define ll long long
#define pi acos(-1)

//priority_queue<int> qu;
queue<int> qu;

typedef pair<int,int> P;

//int a[300005];
int ball[300005];
int ans[300005];
int  k=0;

int main(){
	int n,x;
	scanf("%d",&n);
	memset(ball,0,sizeof(ball));
	int num=1;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(i==n-1)
			break;
		ball[x]=1;
		if(ball[x-1]==1){
			if(x==n){
				num--;
			}
			else{
				if(ball[x+1]==0)
					num++;
				else
					num--;
			}
		}
		else if(ball[x-1]==0){
			if(x<n)
				num++;
		}
		ans[k++]=num;
	}
	printf("1");
	for(int i=0;i<k;i++)
		printf(" %d",ans[i]);
	printf(" 1\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

typedef long int l;
int main() {
    int n; �in >> n;
    map<int, bool> Coins;
    int Sharaga = n;
    cout << 1 << " ";
    for (int i = 1; i <= n; i++) {
        int a; �in >> a;
        Coins[a] = 1;
        if (a == Sharaga) {
            int j = Sharaga - 1;
            while (Coins[j] == 1)
                j--;
            Sharaga = j;
        }
        int Magic = n - Sharaga;
        cout << i + 1 - Magic << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

typedef long int l;
int main() {
    int n; fin >> n;
    map<int, bool> Coins;
    int Sharaga = n;
    cout << 1 << " ";
    for (int i = 1; i <= n; i++) {
        int a; fin >> a;
        Coins[a] = 1;
        if (a == Sharaga) {
            int j = Sharaga - 1;
            while (Coins[j] == 1)
                j--;
            Sharaga = j;
        }
        int Magic = n - Sharaga;
        cout << i + 1 - Magic << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n; cin >> n;
    map<int, bool> Coins;
    int Sharaga = n;
    cout << 1 << " ";
    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        Coins[a] = 1;
        if (a == Sharaga) {
            int j = Sharaga - 1;
            while (Coins[j] == 1)
                j--;
            Sharaga = j;
        }
        int Magic = n - Sharaga;
        cout << i + 1 - Magic << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n = 0; �in >> n;
    map<int, bool> Coins;
    int Sharaga = n;
    cout << 1 << " ";
    for (int i = 1; i <= n; i++) {
        int a; �in >> a;
        Coins[a] = 1;
        if (a == Sharaga) {
            int j = Sharaga - 1;
            while (Coins[j] == 1)
                j--;
            Sharaga = j;
        }
        int Magic = n - Sharaga;
        cout << i + 1 - Magic << " ";
    }
    return 0;
}


#include <map>
#include <iostream>
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main(){
    boostIO();
    int n; cin >> n;
    map<int, bool> Coins;
    int Sharaga = n;
    cout << 1 << " ";
    for (int i = 1; i <= n; ++i) {
        int a; cin >> a;
        Coins[a] = 1;
        if (a == Sharaga) {
            Sharaga--;
            while (Coins[Sharaga] == 1)
                Sharaga--;
        }
        cout << i + 1 - n + Sharaga << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {for(int i=0;i<um;i++) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;

// int par[300005], ran[300005], sum[300005];
bool used[300005];

// void init(int n) {
// 	FOR(i, n) {
// 		par[i] = i;
// 		ran[i] = 0;
// 		sum[i] = 1;
// 	}
// }

// int find(int x) {
// 	if (par[x] == x) return x;
// 	else return par[x] = find(par[x]);
// }

// void unite(int x, int y) {
// 	x = find(x);
// 	y = find(y);
// 	if (x == y) return;
// 	sum[y] = sum[x] = sum[x] + sum[y];
// 	if (ran[x] < ran[y]) {
// 		par[x] = y;
// 	}
// 	else {
// 		par[y] = x;
// 		if (ran[x] == ran[y]) ran[x]++;
// 	}
// }

// bool same(int x, int y) {
// 	return find(x) == find(y);
// }

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	// init(n);
	vector<int> v(n+1, 1);
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		x--;
		used[x] = true;
		if (x-1 >= 0 && used[x-1]) uf(x, x-1);
		if (x+1 < n && used[x+1]) uf(x, x+1);
		if (used[n-1]) v[i] = i-uf.count(n-1)+1;
		else v[i] = i+1;
	}
	FOR(i, n+1) cout << v[i] << (i == n ? "\n" : " ");
	return 0;
}


ぜ#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {for(int i=0;i<um;i++) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;

// int par[300005], ran[300005], sum[300005];
// bool used[300005];

// void init(int n) {
// 	FOR(i, n) {
// 		par[i] = i;
// 		ran[i] = 0;
// 		sum[i] = 1;
// 	}
// }

// int find(int x) {
// 	if (par[x] == x) return x;
// 	else return par[x] = find(par[x]);
// }

// void unite(int x, int y) {
// 	x = find(x);
// 	y = find(y);
// 	if (x == y) return;
// 	sum[y] = sum[x] = sum[x] + sum[y];
// 	if (ran[x] < ran[y]) {
// 		par[x] = y;
// 	}
// 	else {
// 		par[y] = x;
// 		if (ran[x] == ran[y]) ran[x]++;
// 	}
// }

// bool same(int x, int y) {
// 	return find(x) == find(y);
// }

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	// init(n);
	vector<int> v(n+1, 1);
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		x--;
		used[x] = true;
		if (x-1 >= 0 && used[x-1]) uf(x, x-1);
		if (x+1 < n && used[x+1]) uf(x, x+1);
		if (used[n-1]) v[i] = i-uf.count(n-1)+1;
		else v[i] = i+1;
	}
	FOR(i, n+1) cout << v[i] << (i == n ? "\n" : " ");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;
int par[300005], ran[300005], sum[300005];
bool used[300005];

void init(int n) {
	FOR(i, n) {
		par[i] = i;
		ran[i] = 0;
		sum[i] = 1;
	}
}

int find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	sum[y] = sum[x] = sum[x] + sum[y];
	if (ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y]) ran[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	init(n);
	vector<int> v(n+1);
	v[0] = 1;
	FOR(i, n) {
		int x;
		cin >> x;
		x--;
		used[x] = true;
		if (x-1 >= 0 && used[x-1]) unite(x, x-1);
		if (x+1 < n && used[x+1]) unite(x, x+1);
		if (used[n-1]) {
			v[i+1] = (i+2)-sum[find(n-1)];
		}
		else v[i+1] = (i+2);
	}
	FOR(i, n+1) cout << v[i] << (i == n ? "\n" : " ");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;
bool used[300005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	vector<int> v(n+1, 1);
	int pos = n-1;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		x--;
		used[x] = true;
		while (pos >= 0 && used[pos]) pos--;
		v[i] = i-(n-1-pos)+1;
	}
	FOR(i, n+1) cout << v[i] << (i == n ? "\n" : " ");
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=300000+10,maxn=sqrt(N)+10,inf=0x3f3f3f;

int s[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,cnt;
    cin>>n;
    cnt=n;
    cout<<1<<endl;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        s[a]++;
        if(a==cnt)
        {
            while(cnt>0&&s[cnt])cnt--;
        }
        cout<<cnt-n+i+1<<endl;
    }
    return 0;
}
/********************

********************/


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n];
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
    }
    psum[1]==a[1];
    ssum[n-1]==a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]==ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            if(psum[i]==ssum[j] && psum[i]==(psum[j-1]-psum[i])) count++;
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n];
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]==ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            if(psum[i]==ssum[j] && psum[i]==(psum[j-1]-psum[i])) count++;
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]=ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            for(j=i+2; j<n-1;j++)
            {
                if(psum[j]-psum[i]==sum/3) count++;
            }
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=0;
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        if(psum[i]==2*sum/3) ssum[i]=ssum[i+1]+1;
        else ssum[i]==ssum[i+1];
    }
    int count=0;
    if(sum%3==0)
    {
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            count+=ssum[i+1];
        }
    }
    }
    cout<<count;
}


#include<bits/stdc++.h>
using namspace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n];
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
    }
    psum[1]==a[1];
    ssum[n-1]==a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]==ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            if(psum[i]==ssum[j] && psum[i]==(psum[j-1]-psum[i])) count++;
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=0;
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        if(psum[i]==2*sum/3) ssum[i]=ssum[i+1]+1;
    }
    int count=0;
    if(sum%3==0)
    {
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            count+=ssum[i+1];
        }
    }
    }
    cout<<count;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n];
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]=ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            if(psum[i]==ssum[j] && psum[i]==(psum[j-1]-psum[i])) count++;
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=0;
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        if(psum[i]==2*sum/3) ssum[i]=ssum[i+1]+1;
        else ssum[i]=ssum[i+1];
    }
    long long int count=0;
    if(sum%3==0)
    {
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            count+=ssum[i+1];
        }
    }
    }
    cout<<count;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n];
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
    }
    psum[1]=a[1];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]==ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            if(psum[i]==ssum[j] && psum[i]==(psum[j-1]-psum[i])) count++;
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]=ssum[i+1]+a[i];
    }
    int count=0;
    if(sum%3==0)
    {
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            for(int j=i+1; j<n-1;j++)
            {
                if(psum[j]-psum[i]==sum/3) count++;
            }
        }
    }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]=ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            for(int j=i+1; j<n-1;j++)
            {
                if(psum[j]-psum[i]==sum/3) count++;
            }
        }
    }
    cout<<count;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=0;
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        if(psum[i]==2*sum/3) ssum[i]=ssum[i+1]+1;
        else ssum[i]=ssum[i+1];
    }
    int count=0;
    if(sum%3==0)
    {
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            count+=ssum[i+1];
        }
    }
    }
    cout<<count;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n],psum[n],ssum[n],sum=0;
    for(int i=0 ; i< n ;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    psum[0]=a[0];
    ssum[n-1]=a[n-1];
    for(int i=1 ; i<n; i++)
    {
        psum[i]=psum[i-1]+a[i];
    }
    for(int i=n-2;i>-1;i--)
    {
        ssum[i]=ssum[i+1]+a[i];
    }
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        if(psum[i]==sum/3)
        {
            for(int j=i+2; j<n-1;j++)
            {
                if(psum[j]-psum[i]==sum/3) count++;
            }
        }
    }
    cout<<count;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5 * 1e5 + 10 ;

ll n , pre[N],a[N];
vector<int> v;
int main() {
	//scanf("%lld",&n);
	cin >> n;
	pre[0]=0;
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld",&a[i]);
		pre[i]=a[i]+pre[i-1];
	}
	if(pre[n]%3){
		puts("0");
		return 0;
	}
	ll x , y;
	x = pre[n]/3;
	y = x*2;
	for(int i = 1 ; i <= n ; i++)if(pre[i]==x)v.push_back(i);
	ll ans=0;
	for(int i = 1 ; i < n ; i++){
		int z = lower_bound(v.begin(), v.end(), i) - v.begin();
		if(pre[i]==y)ans+=z;
	}
	cout << ans << endl;

	return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int N = 5 * 1e5 + 10 ;

ll n , arr[N],pre[N],a[N];

int main() {
	//scanf("%lld",&n);
	cin >> n;
	pre[0]=0;
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld",&a[i]);
		pre[i]=a[i]+pre[i-1];
	}
	if(pre[n]%3){
		puts("0");
		return 0;
	}
	ll x , y;
	x = pre[n]/3;
	y = x*2;
	for(int i = 1 ; i <= n ; i++){arr[i]=arr[i-1]+(pre[i]==x);}
	int ans=0;
	for(int i = 1 ; i < n ; i++){
		if(pre[i]==y)ans+=arr[i-1];
	}
	printf("%d",ans);
	//cout << ans << endl;

	return 0;
}


#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n, ans , v[MX] , t;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i < n; i++) {
		if (dp[i] == (r / 3)) {
			t++;

		}
		v[i] = t;
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += v[i - 1];
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n,ans;
vector<int> x;

int binary(int z){
	int e = x.size() , s = 0;
	int mid = (s+e)/2;
	if(x.size()==1)return z>x[0];
	while(1){
		if(z>x[mid]) s=mid;
		else if(z==x[mid])return mid;
		else{
			if(x[mid-1]<z)return mid-1;
			else e=mid;
		}
		mid = (s+e)/2;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	int r = dp[n-1];
	if (r % 3 != 0||n<3) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0 ; i < n ; i++){
		if (dp[i] == (r / 3)) {
			x.push_back(i);
		}
	}
	for (int i = n-1; i >=1 ; i--) {
		if(r-dp[i-1]==(r / 3)){
			ans+=binary(i-1);
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n,ans;
vector<int> x;

int binary(int z){
	int e = x.size() , s = 0;
	int mid = (s+e)/2;
	if(x.size()==1)return z>x[0];
	while(1){
		if(z>x[mid]) s=mid;
		else if(z==x[mid])return mid;
		else{
			if(x[mid-1]<z)return mid-1;
			else e=mid;
		}
		mid = (s+e)/2;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	int r = dp[n-1];
	if (r % 3 != 0||n<3) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0 ; i < n ; i++){
		if (dp[i] == (r / 3)) {
			x.push_back(i);
		}
	}
	if(x.size()==0){
		cout << 0 << endl;
		return 0;
	}
	for (int i = n-1; i >=1 ; i--) {
		if(r-dp[i-1]==(r / 3)){
			ans+=binary(i-1);
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5 * 1e5 + 10 ;

ll n , pre[N],a[N];
vector<int> v;
int main() {
	//scanf("%lld",&n);
	cin >> n;
	pre[0]=0;
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld",&a[i]);
		pre[i]=a[i]+pre[i-1];
	}
	if(pre[n]%3){
		puts("0");
		return 0;
	}
	ll x , y;
	x = pre[n]/3;
	y = x*2;
	for(int i = 1 ; i <= n ; i++)if(pre[i]==x)v.push_back(i);
	ll ans=0;
	for(int i = 1 ; i < n ; i++){
		int z = upper_bound(v.begin(), v.end(), i) - v.begin();
		if(pre[i]==y)ans+=z;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
int a[MX], n , v[MX] , t;
ll dp[MX],ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lld",&a[i]);
		if (i == 0)dp[i] = (ll)a[i];
		else dp[i] = dp[i - 1] + (ll)a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		v[i] = t;
		if (dp[i] == (r / 3)) {
			t++;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += (ll)v[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n,ans;
vector<ll> x;

ll binary(ll z){
	int e = x.size() , s = 0;
	int mid = (s+e)/2;
	if(x.size()==1)return z>x[0];
	while(1){
		if(z>x[mid]) s=mid;
		else if(z==x[mid])return mid;
		else{
			if(x[mid-1]<z)return mid-1;
			else e=mid;
		}
		mid = (s+e)/2;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		//cout << a[i] << " ";
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n-1];
	if (r % 3 != 0||n<3) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0 ; i < n ; i++){
		if (dp[i] == (r / 3)) {
			x.push_back(i);
		}
	}
	if(x.size()==0){
		cout << 0 << endl;
		return 0;
	}
	for (int i = n-1; i >=1 ; i--) {
		if(r-dp[i-1]==(r / 3)){
			ans+=binary(i-1);
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int N = 5 * 1e5 + 10 ;

ll n , arr[N],pre[N],a[N];

int main() {
	//scanf("%lld",&n);
	cin >> n;
	pre[0]=0;
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld",&a[i]);
		pre[i]=a[i]+pre[i-1];
	}
	if(pre[n]%3){
		puts("0");
		return 0;
	}
	ll x , y;
	x = pre[n]/3;
	y = x*2;
	for(int i = 1 ; i <= n ; i++){arr[i]=arr[i-1]+(pre[i]==x);}
	ll ans=0;
	for(int i = 1 ; i < n ; i++){
		if(pre[i]==y)ans+=arr[i-1];
	}
	//printf("%d",ans);
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n,ans;
vector<ll> x;

ll binary(ll z){
	int e = x.size() , s = 0;
	int mid = (s+e)/2;
	if(x.size()==1)return z>x[0];
	while(1){
		if(z>x[mid]) s=mid;
		else if(z==x[mid])return mid;
		else{
			if(x[mid-1]<z)return mid-1;
			else e=mid;
		}
		mid = (s+e)/2;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n-1];
	if (r % 3 != 0||n<3) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0 ; i < n ; i++){
		if (dp[i] == (r / 3)) {
			x.push_back(i);
		}
	}
	if(x.size()==0){
		cout << 0 << endl;
		return 0;
	}
	for (int i = n-1; i >=1 ; i--) {
		if(r-dp[i-1]==(r / 3)){
			ans+=binary(i-1);
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
using namespace std;

const int MX = 5 * 100000 + 50;
int a[MX], dp[MX], n,ans1,ans2,ans3;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d ", &a[i]);
		//cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	if (dp[n - 1] % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n - 2; i++) {
		if (dp[i] == dp[n - 1] / 3) {
			ans1++;
		}
	}
	for (int i = 1; i < n-1; i++) {
		if (dp[i] == (dp[n - 1] / 3)*2) {
			ans2++;
		}
	}
	for (int i = 2; i < n ; i++) {
		if (dp[i] == dp[n - 1] ) {
			ans3++;
		}
	}
	cout << ans1*ans2*ans3;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n,ans;
vector<ll> x;

ll binary(ll z){
	int e = x.size() , s = 0;
	int mid = (s+e)/2;
	if(x.size()==1)return z>x[0];
	while(1){
		if(z>x[mid]) s=mid;
		else if(z==x[mid])return mid;
		else{
			if(x[mid-1]<z)return mid-1;
			else e=mid;
		}
		mid = (s+e)/2;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		cout << a[i] << " ";
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n-1];
	if (r % 3 != 0||n<3) {
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0 ; i < n ; i++){
		if (dp[i] == (r / 3)) {
			x.push_back(i);
		}
	}
	if(x.size()==0){
		cout << 0 << endl;
		return 0;
	}
	for (int i = n-1; i >=1 ; i--) {
		if(r-dp[i-1]==(r / 3)){
			ans+=binary(i-1);
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n, ans , v[MX] , t;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lld",&a[i]);
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		v[i] = t;
		if (dp[i] == (r / 3)) {
			t++;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += v[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n, ans , v[MX] , t;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d",a+i);
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		v[i] = t;
		if (dp[i] == (r / 3)) {
			t++;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += v[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
ll a[MX], dp[MX], n, ans , v[MX] , t;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0)dp[i] = a[i];
		else dp[i] = dp[i - 1] + a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		v[i] = t;
		if (dp[i] == (r / 3)) {
			t++;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += v[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX = 5 * 100000 + 50;
int a[MX], n, ans , v[MX] , t;
ll dp[MX];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lld",&a[i]);
		if (i == 0)dp[i] = (ll)a[i];
		else dp[i] = dp[i - 1] + (ll)a[i];
	}
	ll r = dp[n - 1];
	if (r % 3 != 0 || n<3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		v[i] = t;
		if (dp[i] == (r / 3)) {
			t++;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (r - dp[i - 1] == (r / 3)) {
			ans += v[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
	}
	if(n<3){
		cout<<"0";
		return 0;
	}
	int l, r, ans = 0;
	/*for(i=0; i<n; i++){
		cout<<arr[i]<<" ";
	}
	cout<<"\n";
	*/
	for(l = 0; l<=n-3; l++){
		for(r = l+1; r<=n-2; r++){
			//cout<<arr[l]<<" "<<(arr[r] - arr[l])<<" "<<(arr[n-1] - arr[r])<<"\n";
			if(arr[l] == (arr[n-1] - arr[r]) && (arr[l] == (arr[r] - arr[l]))){
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
	}
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	long long l = 0, r = 0, ans = 0;
	for(i=0; i<n-1; i++){
		if(arr[i] == 2*sum) ans += l;
		if(arr[i] == sum) l++;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	int l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	int c = 0;
	cin>>arr[0];
	if(arr[0] == 0) c++;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] == 0) c++;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && c == n){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	long long l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = min(l, r);
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
	}
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	long long l = 0, r = 0, ans = 0;
	for(i=0; i<=n-1; i++){
		if(arr[i] == 2*sum) ans += l;
		if(arr[i] == sum) l++;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	int c = 0;
	cin>>arr[0];
	if(arr[0] == 0) c++;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] == 0) c++;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && c == n){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	long long l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = max(l, r);
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	bool flag = false;
	cin>>arr[0];
	if(arr[0] < 0) flag = false;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] < 0) flag = false;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && flag){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	int l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	int c = 0;
	cin>>arr[0];
	if(arr[0] == 0) c++;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] == 0) c++;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && c == n){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	long long l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	int c = 0;
	cin>>arr[0];
	if(arr[0] == 0) c++;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] == 0) c++;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && c == n){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	int l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	int l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	int c = 0;
	cin>>arr[0];
	if(arr[0] == 0) c++;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] == 0) c++;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && c == n){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	long long l = 0, r = 0, ans = 0;
	for(i=1; i<=n-1; i++){
		if(arr[i] == 2*sum) ans += l;
		if(arr[i] == sum) l++;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[2000001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
	}
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	long long sum = arr[n-1]/3;
	long long l = 0, ans = 0;
	for(i=0; i<n-1; i++){
		//cout<<arr[i]<<" "<<(arr[i] == (2*sum))<<" "<<(arr[i] == sum)<<"\t";
		if(arr[i] == (2*sum)) ans += l;
		if(arr[i] == sum) l++;
		//cout<<l<<" "<<ans<<"\n";
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	cin>>arr[0];
	for(i=1; i<n; i++){
		cin>>arr[i];
		arr[i] += arr[i-1];
	}
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	long long sum = arr[n-1]/3;
	long long l = 0, ans = 0;
	for(i=0; i<n-1; i++){
		//cout<<arr[i]<<" "<<(arr[i] == (2*sum))<<" "<<(arr[i] == sum)<<"\t";
		if(arr[i] == (2*sum)) ans += l;
		if(arr[i] == sum) l++;
		//cout<<l<<" "<<ans<<"\n";
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long arr[200001];

int main(){
	std::ios::sync_with_stdio(false);
	int n, i; cin>>n;
	bool flag = true;
	cin>>arr[0];
	if(arr[0] < 0) flag = false;
	//cout<<arr[0]<<" ";
	for(i=1; i<n; i++){
		cin>>arr[i];
		if(arr[i] < 0) flag = false;
		arr[i] += arr[i-1];
		//cout<<arr[i]<<" ";
	}
	//cout<<"\n";
	if(arr[n-1]%3 != 0 || n<3){
		cout<<"0";
		return 0;
	}
	int sum = arr[n-1]/3;
	//cout<<sum<<"\n";
	if(sum == 0 && flag){
		cout<<(n-1)*(n-2)/2;
		return 0;
	}
	int l = 0, r = 0, ans = 0;
	for(i=0; i<=n-3; i++){
		if(arr[i] == sum) l++;
		if(arr[i] > sum) break;
	}
	for(i=n-2; i>=1; i--){
		if(arr[i] == 2*sum) r++;
		if(arr[i] < 2*sum) break;
	}
	ans = l*r;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long arr[n];
    long long max=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        max+=arr[i];
    }

    long long  amit=0;
    int a=0,b=0,c=0;
    if(max%3==0 )
    {
        for(int i=0; i<n; i++)
        {
            amit+=arr[i];
            if(amit==max/3)a++;
            if(amit==2*max/3)b++;
            if(amit==max)c++;

        }
        if(max==0 && a>=3)
        {
            cout<<(a-2)*(a-3)/2+a-2;

        }

        else if(a==0 || b==0 || c==0)cout<<"0";

        else cout<<a*b*c;

    }
    else cout<<"0";

}


#include <iostream>
#include <map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long  arr[n];
    long long  havana=0;

    map<pair<int,int>, long long > ans;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        havana+=arr[i];
       ans[make_pair(i,i)] = arr[i];
    }
    for(int i=1; i<n; i++)
    {
        for(int j=0; j<n-i; j++)
        {
            ans[make_pair(j,j+i)] =ans[make_pair(j,j+(i-1))]+arr[j+i];
        }
    }
    int rahul=0;

    if(havana%3==0 && n>=3)
    {
    	for(int i=0; i<n-2; i++)
    	{
    		if( ans[make_pair(0,i)]==havana/3)
    		{
    			for(int j=i+1; j<n-1; j++)
    			{
    				if( ans[make_pair(i+1,j)]==havana/3)rahul++;
    			}
    		}
    	}
    	cout<<rahul;
    }
    else cout<<"0";
}