#include using namespace std; using ll=long long; using pii=pair; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) const int N=1000005; int n,a[N],t[N]; bool vis[N]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> n; for(int i=0; i> a[i],vis[a[i]]=1; memset(t,-1,sizeof t); int cur=0; for(int i=0; ia[0]){ while(t[cur]