#define I insert #define D erase #define S second #define V h,u,v,w,x #define U upper_bound #define l get<0>(*O.begin()) #define L get<0>(*O.rbegin()) ll@N,@K,@a[8N],p;set>A,C,E;rep(i,N)A.I({a[i],i}),C.I({a[2N+2i],2i}),C.I({a[2N+2i+1],2i+1}),E.I({a[6N+i],i});set>O;rep(K){auto x=E.begin(),u=A.U({x->first,N}),w=C.U({u->first,2N}),v=w++;O.I({a[N+u->S]+a[4N+v->S]+a[4N+w->S]+a[7N+x->S],u->S,v->S,w->S,x->S});A.D(u),C.D(v),C.D(w),E.D(x);}vectorc,d,s={N,4N,4N,7N},t={0,2N,2N,6N};decltype(A)*P[4]={&A,&C,&C,&E};Rand R;rep(n,3d5){if(n%2){auto&[V]=*O.begin();c={V};}else{auto&[V]=*O.rbegin();c={V};}d=c;p=R.get()%4;auto j=P[p]->begin();REP(R.get()%P[p]->size())j++;if(l<(d[0]=c[0]-a[s[p]+c[p+1]]+a[s[p]+(d[p+1]=j->S)])I({a[t[p]+c[p+1]],c[p+1]}),O.D({c[0],c[1],c[2],c[3],c[4]}),P[p]->D({a[t[p]+d[p+1]],d[p+1]});}}auto j=O.begin(),e=O.end();while(j!=e){auto&[V]=*j++;wt(u+1,v+1,w+1,x+1);}