#define I insert #define D erase #define S second #define V u,v,w,x ll@N,@K,@a[8N],H;set>A,C,E;rep(i,N)A.I({a[i],i+1}),C.I({a[2N+2i],2i}),C.I({a[2N+2i],2i+1}),E.I({a[6N+i],i});set>O;rep(K){auto x=E.begin(),u=A.upper_bound({x->first,N}),v=C.upper_bound({u->first,2N}),w=v++;O.I({a[N+u->S]+a[4N+v->S]+a[4N+w->S]+a[7N+x->S],u->S+1,v->S+1,w->S+1,x->S+1});A.D(u),C.D(v),C.D(w),E.D(x);}REP(n,1d7){if(n%4<1){auto&[h,V]=*O.begin();auto s=C.upper_bound({2N+u,N}),e=C.end();if(s!=e)if(h<(H=h-a[2N+u]+a[2N+s->S]))O.D({h,V}),O.I({H,s->S+1,v,w,x}),C.D(s),C.I({a[2N+u],u});}else if(n%4<2){auto&[h,V]=*O.begin();auto t=C.upper_bound({2N+v,N}),e=C.end();if(t!=e)if(h<(H=h-a[2N+v]+a[2N+t->S]))O.D({h,V}),O.I({H,u,t->S+1,w,x}),C.D(t),C.I({a[2N+v],v});}else if(n%2){auto&[h,V]=*O.rbegin();auto s=C.lower_bound({2N+u,N}),e=C.begin();if(s!=e){s--;if(h>(H=h-a[2N+u]+a[2N+s->S]))O.D({h,V}),O.I({H,s->S+1,v,w,x}),C.D(s),C.I({a[2N+u],u});}}else{auto&[h,V]=*O.rbegin();auto t=C.lower_bound({2N+v,N}),e=C.begin();if(t!=e){t--;if(h>(H=h-a[2N+v]+a[2N+t->S]))O.D({h,V}),O.I({H,u,t->S+1,w,x}),C.D(t),C.I({a[2N+v],v});}}}auto j=O.begin(),e=O.end();while(j!=e){auto&[h,V]=*j++;wt(u,v,w,x);}