#include <bits/stdc++.h>   using namespace std;   void _dbg(string) { cout << endl; }   template <class H, class... T>   void _dbg(string s, H h, T... t) {     int l = s.find( , );     cout << s.substr(0, l) <<   =   << h <<  ,  ;     _dbg(s.substr(l + 1), t...);   }   template <class T, class U>   ostream &operator<<(ostream &o, const pair<T, U> &p) {     o <<  (  << p.first <<  ,  << p.second <<  ) ;     return o;   }   template <class T>   ostream &operator<<(ostream &o, const vector<T> &v) {     o <<  [ ;     for (T t : v) {       o << t <<  , ;     }     o <<  ] ;     return o;   }   class UnionFind {    public:     vector<int> par, rank;     UnionFind(int sz) : par(sz, -1), rank(sz, 0) {}     int find(int x) {       if (par[x] < 0)         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;       if (rank[x] < rank[y]) {         par[y] += par[x];         par[x] = y;       } else {         par[x] += par[y];         par[y] = x;         if (rank[x] == rank[y]) rank[x]++;       }     }     inline bool same(int x, int y) { return find(x) == find(y); }     inline int size(int x) { return -par[find(x)]; }   };   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = (int)(0); i < (int)(n); i++) scanf( %d , &v[i]);     for (int i = (int)(0); i < (int)(n); i++) v[i]--;     UnionFind uf(n + 1);     vector<bool> appeared(n + 1, false);     appeared[n] = true;     cout <<  1  ;     for (int i = (int)(0); i < (int)(n); i++) {       if (v[i] > 0 && appeared[v[i] - 1]) uf.unite(v[i] - 1, v[i]);       if (appeared[v[i] + 1]) uf.unite(v[i], v[i] + 1);       appeared[v[i]] = true;       int sz = uf.size(n) - 1;       printf( %d%c , (i + 2) - sz,    n [i == n - 1]);     }     return 0;   }   