#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd_peekc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos];}) #define rd_getc() ({if(rpos>=rend){usleep(10000);rpos=0;rend=read(0,rbuf,4096);}rbuf[rpos++];}) #define rd() ({int _v=0,_c;while(_c=rd_getc()-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) {unsigned _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;} #define rep(v,e) for(typeof(e)v=0;v=0){ ++c; } if(c>=b){ b=c; x=i; } } x; }); { char*wp=wbuf; rep(i,n){ *wp++='1'; *wp++=' '; wt(x+1); *wp++=' '; wt(i+1); *wp++='\n'; } write(1,wbuf,wp-wbuf); } int y=0; rep(i,n){ if(rd_peekc()=='-'){ rd_getc(); rd_getc(); rd_getc(); y=i; }else{ a[rd()-1]=i; } } rrep(i,n){ b[y]=i; y=a[y]; } { char*wp=wbuf; *wp++='2'; rep(i,n){ *wp++=' '; wt(b[i]+1); } *wp++='\n'; write(1,wbuf,wp-wbuf); } _exit(0); }