#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);}) #define rd_skip() while(*rp++>=48) #define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define WTHI(v) {unsigned _z=v,_n=0;ulong _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;} #define WTLO(v) {unsigned _z=v,_n=8;ulong _d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(ulong*)wp=_d;wp+=8;} #define wt(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);} #define rep(v,e) for(typeof(e) v=0;v=b?a:b) #define chmin(v,a) (v=v<=a?v:a) typedef unsigned long ulong; char wbuf[1<<25]; int n; struct{ unsigned a,b; }ab[200000]; int c[200000]; unsigned z[200000]; void sort_aux(ulong*a,ulong*b,unsigned*c,unsigned*d){ int e[256]; for(int i=0;i<256;++i){ e[i]=0; } for(int i=0;i>8|a[i]<<56; d[k]=c[i]; } } void sort(){ ulong*a=(ulong*)ab; ulong*b=(ulong*)wbuf; unsigned*d=z; sort_aux(a,b,c,d); sort_aux(b,a,d,c); sort_aux(a,b,c,d); sort_aux(b,a,d,c); sort_aux(a,b,c,d); sort_aux(b,a,d,c); sort_aux(a,b,c,d); sort_aux(b,a,d,c); } void f1(){ rd_init(); rd_skip(); rd_skip(); n=rd(); rep(i,n){ ab[i].a=rd(); ab[i].b=rd(); c[i]=i; } sort(); } void f2(){ int pa=ab[0].a; int pb=ab[0].b; int q=pa-pb; z[c[0]]=~0; reps(i,1,n){ unsigned y; if(ab[i].b==ab[i-1].b){ y=ab[i].a-ab[i-1].a; }else{ y=q+ab[i].a+ab[i].b-2; if(ab[i].b==pb+1){ unsigned x=max(ab[i].a,pa); chmin(y,x); } pa=ab[i].a; pb=ab[i].b; } z[c[i]]=y; chmin(q,(int)(ab[i].a-ab[i].b)); } pa=ab[n-1].a; pb=ab[n-1].b; q=pa+pb; rrep(i,n-1){ unsigned y=z[c[i]]; if(ab[i].b==ab[i+1].b){ chmin(y,ab[i+1].a-ab[i].a); }else{ pa=ab[i+1].a; pb=ab[i+1].b; } if(ab[i].b==pb-1){ unsigned x=max(ab[i].a,pa); chmin(y,x); } chmin(y,q+ab[i].a-ab[i].b-2); z[c[i]]=y; chmin(q,ab[i].a+ab[i].b); } } void f3(){ char*wp=wbuf+sizeof wbuf; rrep(i,n){ *--wp='\n'; wt(z[i]); } write(1,wp,wbuf+sizeof wbuf-wp); } int main(){ f1(); f2(); f3(); _exit(0); }