#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,K1,K2,M; int order[101010]; int X[101010],Y[101010]; set> A; set> B; set> ev; int ret[101010]; void fix(int x) { if(x<1 || x>N) return; if(A.count({order[x],x})==0 && B.count({order[x],x})==0) return; int nei=0; if(x>1&&A.count({order[x-1],x-1})==0 && B.count({order[x-1],x-1})==0) nei++; if(x>N>>K1>>K2; if(K1=1) order[K1-i]=x++; if(K2+i<=N) order[K2+i]=x++; } } else { FOR(i,N) { if(K1+i<=N) order[K2+i]=x++; if(K2-i>=1) order[K1-i]=x++; } } FOR(i,N) A.insert({order[i+1],i+1}); cin>>M; FOR(i,M) { cin>>X[i]>>Y[i]; ev.insert({X[i],M+i}); } queue Q; int pret=-1; while(ev.size()) { auto p=*ev.begin(); ev.erase(ev.begin()); if(pret