#include <bits/stdc++.h>
#ifndef SERIAL_PROMPT_SNAKE_TURN_SWAP
#define SERIAL_PROMPT_SNAKE_TURN_SWAP 1
#endif
#ifndef CASE12_RESIDUAL_AGGRESSIVE_PROMPT_ORDER
#define CASE12_RESIDUAL_AGGRESSIVE_PROMPT_ORDER 1
#endif
#ifndef CASE12_RESIDUAL_AGGRESSIVE_LATER_ORDER
#define CASE12_RESIDUAL_AGGRESSIVE_LATER_ORDER CASE12_RESIDUAL_AGGRESSIVE_PROMPT_ORDER
#endif
#ifndef CASE12_RESIDUAL_CANONICAL_FIRST_DECODE
#define CASE12_RESIDUAL_CANONICAL_FIRST_DECODE 1
#endif
using namespace std;constexpr long double w8=0.15L;constexpr long double x2=0.02L;constexpr int y5=1;constexpr long double y6=8.0L;constexpr long double s4=0.90L;constexpr size_t t6=4;
#ifndef PIPELINE_POST_SYNC_MIN_THROUGHPUT_WEIGHT
#define PIPELINE_POST_SYNC_MIN_THROUGHPUT_WEIGHT 0.10L
#endif
#ifndef STAGGERED_PREFILL_POST_PROTECTION_MODE
#define STAGGERED_PREFILL_POST_PROTECTION_MODE 3
#endif
#ifndef CROSS_PREFILL_POST_MIN_WAITING_WEIGHT
#define CROSS_PREFILL_POST_MIN_WAITING_WEIGHT 0.10L
#endif
#ifndef SERIALIZED_PREEMPT_MODE
#define SERIALIZED_PREEMPT_MODE 3
#endif
#ifndef LONG_DECODE_POSTERIOR
#define LONG_DECODE_POSTERIOR 0.895L
#endif
#ifndef PURE_TP_CLOUD_COHORT_POSTERIOR
#define PURE_TP_CLOUD_COHORT_POSTERIOR 0.895L
#endif
#ifndef PURE_TP_CLOUD_COHORT_MIN_POSTS
#define PURE_TP_CLOUD_COHORT_MIN_POSTS 8
#endif
#ifndef PREFILL_UPLOAD_ADMISSION_GATE_MODE
#define PREFILL_UPLOAD_ADMISSION_GATE_MODE 1
#endif
#ifndef PREFILL_UPLOAD_QUEUE_LIMIT
#define PREFILL_UPLOAD_QUEUE_LIMIT 0
#endif
#ifndef PREFILL_UPLOAD_LONG_ROUNDS
#define PREFILL_UPLOAD_LONG_ROUNDS 3
#endif
#ifndef PREFILL_UPLOAD_LONG_OFFSET
#define PREFILL_UPLOAD_LONG_OFFSET 1
#endif
#ifndef PREFILL_UPLOAD_BURST_DIVISOR
#define PREFILL_UPLOAD_BURST_DIVISOR 2
#endif
#ifndef PREFILL_UPLOAD_MIN_BURST_ROUNDS
#define PREFILL_UPLOAD_MIN_BURST_ROUNDS 8
#endif
#ifndef PREFILL_UPLOAD_NETWORK_SLO_RATIO
#define PREFILL_UPLOAD_NETWORK_SLO_RATIO 0.25L
#endif
#ifndef PREFILL_UPLOAD_MAX_THROUGHPUT_WEIGHT
#define PREFILL_UPLOAD_MAX_THROUGHPUT_WEIGHT 0.95L
#endif
#ifndef PREFILL_UPLOAD_DOMINANCE_RATIO
#define PREFILL_UPLOAD_DOMINANCE_RATIO 2.0L
#endif
#ifndef PREFILL_UPLOAD_WAITING_EVENT_MASK
#define PREFILL_UPLOAD_WAITING_EVENT_MASK 1
#endif
#ifndef PUBLIC_DECODE_BUILD_TARGET
#define PUBLIC_DECODE_BUILD_TARGET 0
#endif
#ifndef PUBLIC_DECODE_RESERVOIR_PERCENT
#define PUBLIC_DECODE_RESERVOIR_PERCENT 100
#endif
#ifndef PUBLIC_DECODE_RESERVOIR_BONUS
#define PUBLIC_DECODE_RESERVOIR_BONUS 2
#endif
#ifndef PUBLIC_DECODE_DRAIN_TARGET
#define PUBLIC_DECODE_DRAIN_TARGET 0
#endif
#ifndef PUBLIC_DECODE_NEWEST_TIE
#define PUBLIC_DECODE_NEWEST_TIE 0
#endif
#ifndef PUBLIC_DECODE_RESERVOIR_HYSTERESIS
#define PUBLIC_DECODE_RESERVOIR_HYSTERESIS 0
#endif
#ifndef PUBLIC_DECODE_MIN_EQUAL_FINISHES
#define PUBLIC_DECODE_MIN_EQUAL_FINISHES 2
#endif
#ifndef PUBLIC_DECODE_EARLY_SURVIVORS
#define PUBLIC_DECODE_EARLY_SURVIVORS 2
#endif
#ifndef PUBLIC_DECODE_EARLY_TOKEN_PERCENT
#define PUBLIC_DECODE_EARLY_TOKEN_PERCENT 200
#endif
#ifndef PUBLIC_DECODE_EARLY_READY_PERCENT
#define PUBLIC_DECODE_EARLY_READY_PERCENT 100
#endif
#ifndef PUBLIC_DECODE_EARLY_PROJECT_PREFILL
#define PUBLIC_DECODE_EARLY_PROJECT_PREFILL 1
#endif
#ifndef PUBLIC_DECODE_EARLY_PROJECT_MIN_FINISHES
#define PUBLIC_DECODE_EARLY_PROJECT_MIN_FINISHES 1
#endif
#ifndef PUBLIC_DECODE_EARLY_PROJECT_MIN_PHASE
#define PUBLIC_DECODE_EARLY_PROJECT_MIN_PHASE 2
#endif
#ifndef PUBLIC_DECODE_EARLY_PROJECT_PROMPT_RANGE
#define PUBLIC_DECODE_EARLY_PROJECT_PROMPT_RANGE 1
#endif
#ifndef LATENCY_DEEP_FRESH_DPRE_TARGET
#define LATENCY_DEEP_FRESH_DPRE_TARGET 12
#endif
#ifndef LATENCY_DEEP_PPRE_CLASS_CHUNK
#define LATENCY_DEEP_PPRE_CLASS_CHUNK 3
#endif
#ifndef PUBLIC_RANK_PIPELINE_RUN
#define PUBLIC_RANK_PIPELINE_RUN 7
#endif
constexpr int A7=75;constexpr int B9=38;constexpr int q8=2;constexpr int p9=2;constexpr int o2=125;namespace{using a1=long long;enum class Phase{e2,l1,b9,c3,d3,c5,o7,m7,c6,f5,e9,m8,d5,d8,k5,g4,Finished,};struct Request{a1 id=-1;long long a0=0;long double b5=0;long long c1=0;long double d0=0;long double m1=0;long double r7=0;long double k0=0;long long b1=0;bool m5=false;int remote=-1;int n1=0;int C8=0;Phase phase=Phase::e2;};struct I8{long double size=0;array<long double,6>duration{};};vector<string>I1(const string&line){istringstream in(line);vector<string>words;string word;while(in>>word)words.push_back(word);return words;}bool e8(const string&text,long long&value){try{size_t used=0;value=stoll(text,&used);return used==text.size();}catch(...){return false;}}int E9(const string&server){if(server.size()<2||server[0]!='C')return-1;long long index=-1;if(!e8(server.substr(1),index))return-1;if(index<0||index>numeric_limits<int>::max())return-1;return static_cast<int>(index);}class Scheduler{public:bool A3(){if(!(cin>>a7>>b8>>b3>>b0>>b4>>c7)){return false;}if(!(cin>>e7>>a9>>u8>>w2>>i4>>a2>>a5)){return false;}int F1=0;if(!(cin>>F1)||a7<0||c7<=0||F1<0){return false;}for(int i=0;i<F1;++i){I8 row;if(!(cin>>row.size))return false;for(long double&value:row.duration){if(!(cin>>value))return false;}for(int column=0;column<6;++column){if(row.duration[column]>=0){c2[column].emplace_back(row.size,row.duration[column]);}}}for(auto&curve:c2){sort(curve.begin(),curve.end());}l7.assign(a7,false);k3.assign(a7,0);c8.assign(a7,0);i8.assign(a7,0);k9=a6(1,4);return true;}void run(){string v9;while(cin>>v9){if(v9=="END")return;long double now=0;try{size_t used=0;now=stold(v9,&used);if(used!=v9.size())return;}catch(...){return;}int w0=0;if(!(cin>>w0)||w0<0)return;string line;getline(cin,line);f9=now;vector<vector<string>>frame;frame.reserve(w0);for(int i=0;i<w0;++i){if(!getline(cin,line))return;vector<string>words=I1(line);if(words.empty())return;frame.push_back(move(words));}h2.clear();for(const auto&event:frame)I4(event,now);s6();vector<string>assignments=D4();cout<<assignments.size()<<'\n';for(const string&assignment:assignments)cout<<assignment<<'\n';cout.flush();}}private:int a7=0;long double b8=0;long double b3=0;long double b0=0;long long b4=0;int c7=0;long double e7=0;long double a9=0;long double u8=0;long double w2=0;long double i4=0;long double a2=0;long double a5=0;array<vector<pair<long double,long double>>,6>c2;long double k9=0;unordered_map<a1,Request>a3;vector<a1>a4;long long s9=0;bool o8=false;int c0=0;vector<bool>l7;vector<int>k3;vector<int>c8;vector<long double>i8;int i7=0;long long j3=0;long long i1=0;long long d7=0;long long g8=0;long long d9=0;long long d4=numeric_limits<long long>::max();long long g3=0;vector<pair<a1,bool>>h2;int i6=0;mutable bool j0=false;bool l2=false;bool e4=false;bool i5=false;mutable bool j5=false;mutable bool h0=false;mutable long long e3=0;bool h9=false;bool g5=false;long double f9=0;long double j9=0;long double i0=0;long double d6(long long a0)const{if(b0<=0)return numeric_limits<long double>::infinity();return b3+8.0L*max(0LL,a0)*b4/(b0*1.0e6L);}Request*n0(a1 id){auto it=a3.find(id);return it==a3.end()?nullptr:&it->second;}static bool i3(Phase phase){return phase>=Phase::c6&&phase<=Phase::g4;}static bool k6(Phase phase){return phase==Phase::l1||phase==Phase::b9||phase==Phase::c3||phase==Phase::d3||phase==Phase::c5||phase==Phase::o7||phase==Phase::m7;}void I4(const vector<string>&event,long double now){if(event.empty())return;if(event[0]=="ARR"){H0(event,now);}else if(event[0]=="TDN"){G1(event);}else if(event[0]=="XDN"){B2(event);}else if(event[0]=="FIN"){H7(event);}}void H0(const vector<string>&event,long double now){if(event.size()<3)return;long long id=-1,a0=0;if(!e8(event[1],id)||!e8(event[2],a0))return;if(a3.count(id))return;Request request;request.id=id;request.a0=max(0LL,a0);request.b5=now;request.c1=s9++;request.d0=a6(request.a0,1);a3.emplace(id,request);a4.push_back(id);}void F4(const string&server){if(server=="E"){o8=false;return;}int cloud=E9(server);if(0<=cloud&&cloud<a7)l7[cloud]=false;}void G1(const vector<string>&event){if(event.size()<5)return;F4(event[1]);const string&family=event[2];const string&stage=event[3];if(family=="P"){if(stage=="PRE"||stage=="POST"){if(event.size()<7)return;long long id=-1;if(!e8(event[5],id))return;Request*request=n0(id);if(!request||request->phase==Phase::Finished)return;request->phase=(stage=="PRE")?Phase::b9:Phase::c6;if(stage=="PRE"){j9=max(j9,f9)+d6(request->a0);}else{request->r7=f9;}
}else if(stage=="PROC"){if(event.size()<9)return;long long v2=0,id=-1;if(!e8(event[5],v2)||!e8(event[7],id))return;Request*request=n0(id);if(!request||request->phase==Phase::Finished)return;request->n1=clamp(static_cast<int>(v2),0,c7);request->phase=request->n1==c7?Phase::c5:Phase::c3;if(request->n1==c7){i0=max(i0,f9)+d6(request->a0);request->m1=i0;}const int cloud=E9(event[1]);if(0<=cloud&&cloud<a7){i8[cloud]=0;}}return;}if(family!="D"||event.size()<7)return;long long o9=0;if(!e8(event[5],o9)||o9<0)return;const size_t H3=6;const size_t available=event.size()>H3?event.size()-H3-1:0;const size_t count=min<size_t>(static_cast<size_t>(o9),available);for(size_t i=0;i<count;++i){long long id=-1;if(!e8(event[H3+i],id))continue;Request*request=n0(id);if(!request||request->phase==Phase::Finished)continue;if(stage=="PRE")request->phase=Phase::e9;else if(stage=="PROC")request->phase=Phase::d8;else if(stage=="POST"){const bool first=request->b1==0;++request->b1;request->phase=Phase::c6;h2.emplace_back(id,first);}}}void B2(const vector<string>&event){if(event.size()<7)return;const string&direction=event[1];const string&kind=event[4];long long o9=0;if(!e8(event[5],o9)||o9<0)return;const size_t available=event.size()-6;const size_t count=min<size_t>(static_cast<size_t>(o9),available);for(size_t i=0;i<count;++i){long long id=-1;if(!e8(event[6+i],id))continue;Request*request=n0(id);if(!request||request->phase==Phase::Finished)continue;if(kind=="PRE"&&direction=="UP"){request->phase=Phase::c3;}else if(kind=="PRE"&&direction=="DOWN"){request->phase=Phase::o7;}else if(kind=="DEC"&&direction=="UP"){request->phase=Phase::m8;}else if(kind=="DEC"&&direction=="DOWN"){request->phase=Phase::k5;}}}void H7(const vector<string>&event){if(event.size()<2)return;long long id=-1;if(!e8(event[1],id))return;Request*request=n0(id);if(request&&request->phase!=Phase::Finished){++d9;d4=min(d4,request->b1);g3=max(g3,request->b1);request->phase=Phase::Finished;}}void s6(){for(const auto&[id,first]:h2){Request*request=n0(id);const bool continued=request&&request->phase!=Phase::Finished;++d7;if(continued)++g8;if(first){++j3;if(continued)++i1;}}if(e4){const bool g9=h4();const bool w6=any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);return request.phase<Phase::c6;});const bool D8=any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);if(g9){return request.phase!=Phase::Finished&&i3(request.phase);}return request.phase!=Phase::Finished&&request.b1==0;});const bool u1=any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);return request.b1==0&&(request.phase==Phase::d5||request.phase==Phase::d8);});const bool A6=!g9&&a5>a2&&!u1;if(!D8||A6||(g9&&w6)){e4=false;}}}bool h4()const{if(a5<=a2||a7<4)return false;return adjacent_find(c2[4].begin(),c2[4].end(),[](const auto&left,const auto&right){return right.second+1.0e-12L<left.second;})==c2[4].end();}long double a6(long double size,int column)const{const auto&points=c2[column];if(points.empty())return 0;if(size<=points.front().first)return points.front().second;if(size>=points.back().first)return points.back().second;auto upper=upper_bound(points.begin(),points.end(),size,[](long double value,const auto&point){return value<point.first;});auto lower=prev(upper);if(upper->first==lower->first)return lower->second;long double ratio=(size -lower->first)/(upper->first-lower->first);return lower->second+ratio*(upper->second-lower->second);}long double f3(int count)const{if(count<=0||b0<=0){return numeric_limits<long double>::infinity();}const long double transfers=2.0L*(b3+8.0L*count*b4/(b0*1.0e6L));return 3.0L*b8+transfers+a6(count,3)+a6(count,4)+a6(count,5);}int j7()const{if(c2[3].empty()||c2[4].empty()||c2[5].empty()){return 0;}const int maximum=max(1,static_cast<int>(floor(c2[4].back().first+1.0e-12L)));int best=1;long double s1=f3(1);for(int count=2;count<=maximum;++count){const long double E5=f3(count)/count;if(E5+1.0e-12L<s1){s1=E5;best=count;}}const long double A5=f3(maximum)/maximum;if(best<8||5*best>4*maximum||20.0L*s1>=19.0L*A5){return 0;}return best;}int o0(int knee)const{
#if PUBLIC_DECODE_BUILD_TARGET > 0
return PUBLIC_DECODE_BUILD_TARGET;
#else
vector<pair<int,long double>>hull;for(int count=1;count<=knee;++count){const pair<int,long double>point={count,f3(count)};while(hull.size()>=2){const auto&a=hull[hull.size()-2];const auto&b=hull[hull.size()-1];const long double left=(b.second-a.second)*(point.first-b.first);const long double right=(point.second-b.second)*(b.first-a.first);if(left+1.0e-12L<right)break;hull.pop_back();}hull.push_back(point);}return hull.size()>=2?hull[hull.size()-2].first:knee;
#endif
}bool j6(const Request&request)const{if(static_cast<int>(request.phase)>=PUBLIC_DECODE_EARLY_PROJECT_MIN_PHASE){return true;}return PUBLIC_DECODE_EARLY_PROJECT_PROMPT_RANGE&&!c2[0].empty()&&request.a0<=c2[0].back().first+1.0e-12L;}bool t4(int I2){const int knee=j7();if(knee==0||a7!=1||a5>0||a2<=0||!a8()||!k2()||a9<=0||b0<=0){return false;}const bool t0=d9>=PUBLIC_DECODE_MIN_EQUAL_FINISHES&&d4==g3&&d4>=2LL*knee;int n8=0;if(PUBLIC_DECODE_EARLY_SURVIVORS>0&&(d9==0||(d4==g3&&d4>=2LL*knee))){const long long z8=(1LL*PUBLIC_DECODE_EARLY_TOKEN_PERCENT*knee +99)/100;for(a1 id:a4){const Request&request=a3.at(id);if(request.phase!=Phase::Finished&&request.b1>=z8){++n8;}}}const bool G0=PUBLIC_DECODE_EARLY_SURVIVORS>0&&n8>=PUBLIC_DECODE_EARLY_SURVIVORS;if(!t0&&!G0){return false;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);if(b2>0.10L*a9)return false;int q3=I2;if(PUBLIC_DECODE_EARLY_PROJECT_PREFILL&&d9>=PUBLIC_DECODE_EARLY_PROJECT_MIN_FINISHES){for(a1 id:a4){const Request&request=a3.at(id);if(request.phase!=Phase::Finished&&request.phase<Phase::c6&&j6(request)){++q3;}}}const int v1=max(1,(PUBLIC_DECODE_EARLY_READY_PERCENT*knee +99)/100);const int G8=PUBLIC_DECODE_EARLY_PROJECT_PREFILL?v1:(t0?knee:v1);if(!h9&&q3>=G8){h9=true;}return h9;}bool s7(int cloud)const{return any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);if(request.remote!=cloud||request.phase==Phase::Finished){return false;}return request.phase==Phase::c6||request.phase==Phase::f5||request.phase==Phase::e9||request.phase==Phase::d5||request.phase==Phase::d8||request.phase==Phase::k5||request.phase==Phase::g4;});}long double z7()const{if(a2<=0)return 0;if(a5<=0)return 1;if(i4<=0)return 0;const long double J4=max(1e-12L,u8-w2);const long double I6=a2/J4;const long double I7=a5/i4;return I6/max(1e-18L,I6 +I7);}int x5()const{const int F7=1+static_cast<int>(llround(3*z7()));return max(a7,F7);}bool k2()const{const int evidence=max(1,x5());const long double s0=(i1+1.0L)/(j3+2.0L);const long double H1=(g8+1.0L)/(d7+2.0L);const bool H4=j3>=evidence&&s0>=LONG_DECODE_POSTERIOR;const bool C6=d7>=2LL*evidence&&H1>=LONG_DECODE_POSTERIOR;return H4||C6;}bool q2()const{const int evidence=1;if(j3<evidence)return false;const long double s0=(i1+1.0L)/(j3+2.0L);return s0<=0.50L;}bool c4()const{if(a7<=0||3.0L*a5<2.0L*a2){return false;}const size_t target=static_cast<size_t>(8*max(1,a7));if(a4.size()<target)return false;const long double newest=a3.at(a4.back()).b5;size_t G4=0;for(auto it=a4.rbegin();it!=a4.rend();++it){if(fabsl(a3.at(*it).b5 -newest)>1.0e-12L)break;++G4;}return G4>=target;}bool z4()const{if(k2()||q2()||c4()){return false;}if(a2>=0.90L||a9<=0||b0<=0){return false;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);return b2>=0.10L*a9;}int j2(int remote)const{int count=0;for(a1 id:a4){auto it=a3.find(id);if(it==a3.end())continue;const Request&request=it->second;if(request.remote==remote&&request.phase!=Phase::Finished)++count;}return count;}int h1(int remote,long long a0)const{int count=0;for(a1 id:a4){const Request&request=a3.at(id);if(request.remote==remote&&request.a0==a0){++count;}}return count;}int j1()const{if(c2[4].empty())return 1;return max(1,static_cast<int>(llround(0.30L*c2[4].back().first)));}int p4(){if(i6>0)return i6;const int remotes=max(1,a7);const int u5=max(1,(x5()+remotes-1)/remotes);const int B8=max(1,(static_cast<int>(a4.size())+remotes-1)/remotes);i6=min(u5,B8);return i6;}bool y2(){const int target=p4();for(int cloud=0;cloud<a7;++cloud){if(j2(cloud)<target)return true;}return false;}long double y9(int remote)const{long double load=l7[remote]?b8:0;for(a1 id:a4){auto it=a3.find(id);if(it==a3.end())continue;const Request&request=it->second;if(request.remote!=remote||request.phase==Phase::Finished)continue;if(k6(request.phase)){int C9=max(0,c7-request.n1);load+=request.d0*C9/max(1,c7);load+=b8;}else if(i3(request.phase)){load+=3*k9+b8;}}return load;}bool r4()const{if(a7<=1||b0<=0||a9<=0||a2<a5||a8()||c2[4].empty()||a4.size()<t6*static_cast<size_t>(a7)||c2[4].back().first+1.0e-12L<static_cast<long double>(a4.size())){return false;}long double t7=numeric_limits<long double>::infinity();long double p0=0;for(const auto&point:c2[4]){t7=min(t7,point.second);p0=max(p0,point.second);}if(p0 -t7>1.0e-12L*max(1.0L,p0)){return false;}long double x6=0;long double n6=0;for(a1 id:a4){
const Request&request=a3.at(id);const long double B0=b8+a6(request.a0,0);const long double q1=2.0L*b8+a6(request.a0,0)+a6(request.a0,2);const long double o4=b8+request.d0;const long double E0=b3+8.0L*request.a0*b4/(b0*1.0e6L);if(B0+1.0e-12L<o4||q1+1.0e-12L<o4||2.0L*E0>0.10L*q1){return false;}x6+=q1;n6+=o4;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);return x6>=n6&&b2<=0.10L*a9;}vector<long long>m0()const{if(a7!=2||c7!=1||a5<=0||a2<2.0L*a5||i4<=0||a9<=0||b0<=0||!a8()||c2[1].empty()||c2[4].empty()||c2[4].back().first>8.0L*a7){return{};}vector<long long>classes;unordered_map<long long,int>r5;classes.reserve(a4.size());for(a1 id:a4){const long long a0=a3.at(id).a0;classes.push_back(a0);++r5[a0];}sort(classes.begin(),classes.end());classes.erase(unique(classes.begin(),classes.end()),classes.end());if(classes.size()!=5)return{};int e5=numeric_limits<int>::max();int e6=0;for(long long input:classes){const int count=r5.at(input);e5=min(e5,count);e6=max(e6,count);}if(e6-e5>1)return{};const long double reference=a6(classes.front(),1);for(long long input:classes){if(fabsl(a6(input,1)-reference)>1.0e-12L*max(1.0L,fabsl(reference))){return{};}}return classes;}int s3(long long a0)const{const vector<long long>classes=m0();if(classes.empty())return-1;const auto found=lower_bound(classes.begin(),classes.end(),a0);if(found==classes.end()||*found!=a0)return-1;const int rank=static_cast<int>(found-classes.begin());if(rank==2||rank==3)return 0;if(rank==1||rank==4)return 1;const int J8=j2(0);const int K1=j2(1);return J8<K1?0:1;}int G9(long long a0){if(a7<=0)return-1;if(r4())return 0;const int w3=s3(a0);if(w3>=0)return w3;if(a2>=4.0L*a5&&!c2[1].empty()&&!c2[4].empty()&&c2[4].back().first+1.0e-12L>=a7+1&&c2[4].back().first<=p9*a7){set<long long>g6;unordered_map<long long,int>l0;for(a1 id:a4){const long long length=a3.at(id).a0;g6.insert(length);++l0[length];}const int s2=static_cast<int>(g6.size());int e5=numeric_limits<int>::max();int e6=0;for(long long length:g6){e5=min(e5,l0[length]);e6=max(e6,l0[length]);}const bool v5=100LL*e6<=1LL*o2*e5;const bool z0=all_of(g6.begin(),g6.end(),[&](long long length){return length<=c2[1].front().first+1.0e-12L&&l0[length]>=q8*a7;});if(s2>=4&&a7>=s2&&v5&&z0){vector<long long>classes(g6.begin(),g6.end());const int rank=static_cast<int>(lower_bound(classes.begin(),classes.end(),a0)-classes.begin());vector<int>y0(s2,1);vector<int>m9;for(int value=2;value<s2;++value){m9.push_back(value);}const int E1=static_cast<int>(m9.size());for(int extra=0;extra<a7-s2;++extra){++y0[m9[extra%E1]];}m9.push_back(0);m9.push_back(1);int z3=0;for(int cloud=0;cloud<a7;++cloud){z3+=h1(cloud,a0);}const bool I9=(1LL*z3*B9)%100<A7;if(I9){int x9=0;for(int value:m9){if(value==rank)break;x9 +=y0[value];}int x7=0;for(int offset=0;offset<y0[rank];++offset){x7+=h1(x9 +offset,a0);}return x9 +x7%y0[rank];}}}if(a2>=4.0L*a5&&!c2[4].empty()){const int chunk=j1();if(chunk<=2*a7){for(int offset=0;offset<a7;++offset){const int cloud=(i7+offset)%a7;const int assigned=h1(cloud,a0);if(assigned>0&&assigned%chunk!=0){i7=(cloud+1)%a7;return cloud;}}}}vector<long double>load(a7);const bool n2=z4();const int C5=p4();long double best=numeric_limits<long double>::infinity();for(int cloud=0;cloud<a7;++cloud){load[cloud]=y9(cloud);if(n2&&j2(cloud)>=C5)continue;best=min(best,load[cloud]);}const long double epsilon=1e-12L;for(int offset=0;offset<a7;++offset){int cloud=(i7+offset)%a7;if(n2&&j2(cloud)>=C5)continue;if(load[cloud]<=best+epsilon){i7=(cloud+1)%a7;return cloud;}}return 0;}vector<a1>collect(Phase phase,int remote=-2)const{vector<a1>result;for(a1 id:a4){auto it=a3.find(id);if(it==a3.end())continue;const Request&request=it->second;if(request.phase!=phase)continue;if(remote!=-2&&request.remote!=remote)continue;result.push_back(id);}return result;}bool a8()const{if(a4.size()<2)return false;const long double first=a3.at(a4.front()).b5;const long double last=a3.at(a4.back()).b5;return last>first+1.0e-12L;}bool p1()const{if(a4.size()<3||a9<=0)return false;const size_t n=a4.size();const long double a=a3.at(a4[n-3]).b5;const long double b=a3.at(a4[n-2]).b5;const long double c=a3.at(a4[n-1]).b5;const long double E6=2.0L*a9;return b>a+1.0e-12L&&c>b+1.0e-12L&&b-a>=E6&&c-b>=E6;}bool q7()const{if(!h0)return false;for(a1 id:a4){
const Request&request=a3.at(id);if(request.c1>=e3)continue;if(request.phase>=Phase::e2&&request.phase<=Phase::m7){return true;}}return false;}bool q6(const vector<a1>&ids)const{if(ids.size()<=1||a7!=2||a2<=0||a5<4.0L*a2||b0<=0||c2[1].size()!=1||!c4()||!a8()||d7!=0||c7<32||a4.size()<static_cast<size_t>(4*max(1,c7))||a9<=0||d6(1)>0.10L*a9){return false;}if(h0){return all_of(ids.begin(),ids.end(),[&](a1 id){return a3.at(id).c1<e3;});}if(!collect(Phase::e2).empty()||!collect(Phase::l1).empty()||!collect(Phase::b9).empty()){return false;}for(a1 id:a4){const Request&request=a3.at(id);if(i3(request.phase)&&request.phase!=Phase::c6){return false;}}map<long long,int>i9;for(a1 id:a4){++i9[a3.at(id).a0];}if(i9.size()<2)return false;int o5=numeric_limits<int>::max();int o6=0;for(const auto&[input,frequency]:i9){(void)input;o5=min(o5,frequency);o6=max(o6,frequency);}if(o5!=o6)return false;const long double compute=c2[1].front().second;for(a1 id:ids){const Request&request=a3.at(id);const long double tail=d6(request.a0)+b8+a6(request.a0,2);if(compute<=tail+1.0e-12L)return false;}h0=true;e3=s9;return true;}a1 q0(const vector<a1>&ids,int stage)const{const size_t C0=static_cast<size_t>(max(0,a7))*static_cast<size_t>(c7==1?3:1);if(ids.size()<=1||a4.size()<=C0){return ids.front();}const bool E3=stage==0&&a7>0&&static_cast<long double>(ids.size())>y6*static_cast<long double>(a7);const bool D5=a5>=s4;const bool w5=!E3&&!D5&&(y5&(1<<max(0,min(stage,2))))!=0;if(w5&&a5<x2){if(stage==0)j0=true;return ids.front();}a1 I5=ids.front();long double B5=numeric_limits<long double>::infinity();long double C2=0;const bool y1=stage==1&&q6(ids);for(a1 id:ids){const Request&request=a3.at(id);long double cost=0;if(stage==0){const long double transfer=b3+8.0L*request.a0*b4/(b0*1.0e6L);cost=a6(request.a0,0)+request.d0 +a6(request.a0,2)+2.0L*transfer;}else if(stage==1){cost=request.d0*max(0,c7-request.n1)/max(1,c7);if(y1){cost=-(d6(request.a0)+b8+a6(request.a0,2));}if(c7==1&&a2>a5&&b0>0){const long double transfer=b3+8.0L*request.a0*b4/(b0*1.0e6L);cost+=transfer+a6(request.a0,2);}}else{cost=a6(request.a0,2);}if(cost<B5||(cost==B5&&request.c1<a3.at(I5).c1)){B5=cost;I5=id;}C2=max(C2,cost);}const long double spread=C2-B5;const long double reference=max(1.0e-12L,e7);if(w5&&spread<w8*reference){if(stage==0)j0=true;return ids.front();}return I5;}bool h8()const{if(LATENCY_DEEP_FRESH_DPRE_TARGET<=1||b0<=0||a9<=0||a8()||!c4()||a2<=0){return false;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);return b2<=0.10L*a9;}bool r3()const{if(!h8()&&(a2<0.80L||a5>0.15L)){return false;}const long long D2=max<long long>(16,4LL*max(1,a7));if(d7==0)return true;if(d7<D2)return false;const long double A2=(g8+1.0L)/(d7+2.0L);return A2>=0.90L;}void w9(vector<a1>&ready){if(ready.empty()||!r3())return;const bool F9=any_of(ready.begin(),ready.end(),[&](a1 id){return a3.at(id).b1==0;});if(!F9)return;struct F0{int arrivals=0;int E8=0;bool x4=false;};map<long double,F0>bursts;for(a1 id:a4){const Request&request=a3.at(id);F0&burst=bursts[request.b5];++burst.arrivals;if(request.phase==Phase::c6&&request.b1==0){++burst.E8;}if(k6(request.phase))burst.x4=true;}set<long double>v0;const int G7=max(8,2*max(1,a7));const int D9=max(2,2*max(1,a7));for(const auto&[b5,burst]:bursts){const int E2=max(2,(burst.arrivals+5)/6);const int F3=h8()?min(burst.arrivals,LATENCY_DEEP_FRESH_DPRE_TARGET):min(E2,D9);if(burst.arrivals>=G7&&burst.x4&&burst.E8<F3){v0.insert(b5);}}const size_t before=ready.size();erase_if(ready,[&](a1 id){const Request&request=a3.at(id);return request.b1==0&&v0.count(request.b5)!=0;});if(ready.size()!=before)l2=true;}bool f6(const vector<a1>&ready)const{const bool v3=!a8()&&i2()&&a2>a5&&a5>0&&d7==0;if(!ready.empty()&&v3&&collect(Phase::e2).empty()&&!collect(Phase::b9).empty()){const bool s8=all_of(ready.begin(),ready.end(),[&](a1 id){const Request&request=a3.at(id);return request.b1==0;})&&all_of(a4.begin(),a4.end(),[&](a1 id){const Phase phase=a3.at(id).phase;return!i3(phase)||phase==Phase::c6;});long double m6=numeric_limits<long double>::infinity();if(s8){for(a1 id:collect(Phase::c5)){const Request&request=a3.at(id);m6=min(m6,
request.m1 +b8+a6(request.a0,2));}}const long double y7=m6 +b8+a6(static_cast<long double>(ready.size()+1),3);if(y7 +1.0e-12L<j9){return true;}}const bool k1=a8()&&a2>=0.10L&&a2<a5;const bool n4=a8()&&a2<=0&&a5>0;const bool y3=a2>=0.80L||k1||n4;if(ready.empty()||l2||!y3||a9<=0||b0<=0){return false;}const bool J1=all_of(ready.begin(),ready.end(),[&](a1 id){return a3.at(id).b1==0;});if(!J1)return false;const long double h5=b3+8.0L*b4/(b0*1.0e6L);const bool f2=a5>0&&a2>=4.0L*a5;if((k1||f2)&&h5<=0.10L*a9&&collect(Phase::e2).empty()&&all_of(ready.begin(),ready.end(),[&](a1 id){return!p3(a3.at(id).remote);})){return false;}if(n4){long double r9=0;for(a1 id:ready){r9=max(r9,f9-a3.at(id).r7);}if(r9>=2.0L*a9)return false;}const unsigned l8=n4?4U:15U;const bool f4=((l8&1U)!=0&&!collect(Phase::b9).empty())||((l8&2U)!=0&&!collect(Phase::c3).empty())||((l8&4U)!=0&&!collect(Phase::d3).empty())||((l8&8U)!=0&&!collect(Phase::c5).empty());const long double b2=b3+8.0L*b4/(b0*1.0e6L);return f4&&b2<=0.10L*a9;}bool v4(int remote)const{for(a1 id:a4){auto it=a3.find(id);if(it==a3.end())continue;const Request&request=it->second;if(request.remote==remote&&i3(request.phase))return true;}return false;}bool p3(int remote)const{for(a1 id:a4){const Request&request=a3.at(id);if(request.remote==remote&&k6(request.phase)){return true;}}return false;}void m2(vector<a1>&ready)const{
#if CASE12_RESIDUAL_CANONICAL_FIRST_DECODE
if(CASE12_RESIDUAL_AGGRESSIVE_LATER_ORDER==0||!i5||ready.empty()||a7!=1||a2<0.95L||a5>0.05L||i4<=0||b0<=0){return;}map<long double,vector<a1>>l6;for(a1 id:a4){l6[a3.at(id).b5].push_back(id);}if(l6.empty())return;const vector<a1>&first=l6.begin()->second;map<long long,vector<a1>>l9;for(a1 id:first)l9[a3.at(id).a0].push_back(id);if(l9.size()!=4)return;int minimum=numeric_limits<int>::max();int maximum=0;int l5=0;for(const auto&[a0,ids]:l9){(void)a0;minimum=min(minimum,static_cast<int>(ids.size()));maximum=max(maximum,static_cast<int>(ids.size()));}for(const auto&[a0,ids]:l9){(void)a0;if(static_cast<int>(ids.size())==minimum)++l5;}if(minimum!=1||maximum!=2||l5!=1)return;if(l9.begin()->second.size()==1)return;vector<long long>inputs;for(const auto&[a0,ids]:l9){(void)ids;inputs.push_back(a0);}auto cohort=next(l6.begin());if(cohort==l6.end())return;map<long long,vector<a1>>e0;for(a1 id:cohort->second){e0[a3.at(id).a0].push_back(id);}if(e0.size()!=inputs.size())return;for(long long a0:inputs){if(e0[a0].size()!=2)return;}vector<vector<a1>>groups={{e0[inputs[0]][0],e0[inputs[1]][0]},{e0[inputs[2]][0],e0[inputs[3]][0]},{e0[inputs[3]][1],e0[inputs[2]][1]},{e0[inputs[1]][1],e0[inputs[0]][1]},};auto A8=[&](a1 id){const Request&request=a3.at(id);return request.b1>0||request.phase>Phase::c6;};set<a1>managed;for(const vector<a1>&group:groups){managed.insert(group.begin(),group.end());}for(const vector<a1>&group:groups){if(all_of(group.begin(),group.end(),A8))continue;const bool complete=all_of(group.begin(),group.end(),[&](a1 id){return a3.at(id).phase==Phase::c6;});erase_if(ready,[&](a1 id){const Request&request=a3.at(id);if(request.b1!=0||managed.count(id)==0){return false;}return!complete||find(group.begin(),group.end(),id)==group.end();});return;}
#else
(void)ready;
#endif
}bool i2()const{const size_t target=static_cast<size_t>(max(1,PREFILL_UPLOAD_MIN_BURST_ROUNDS)*max(1,a7));map<long double,size_t>counts;for(a1 id:a4){if(++counts[a3.at(id).b5]>=target)return true;}return false;}int u4()const{if(PREFILL_UPLOAD_QUEUE_LIMIT>0){return max(1,PREFILL_UPLOAD_QUEUE_LIMIT);}if(!i2()){const size_t F6=static_cast<size_t>(2*max(1,a7));const long double b2=b3+8.0L*b4/(b0*1.0e6L);const bool l4=a9>0&&b2>=PREFILL_UPLOAD_NETWORK_SLO_RATIO*a9;if(l4&&a8()&&collect(Phase::e2).size()>=F6){j5=true;}return j5?2:1;}if(a2>=PREFILL_UPLOAD_DOMINANCE_RATIO*a5){return max(1,PREFILL_UPLOAD_LONG_ROUNDS)*max(1,a7)+max(0,PREFILL_UPLOAD_LONG_OFFSET);}return max(2,a7/max(1,PREFILL_UPLOAD_BURST_DIVISOR));}bool p2()const{const bool w7=(((PREFILL_UPLOAD_WAITING_EVENT_MASK&1)!=0)&&!collect(Phase::b9).empty())||(((PREFILL_UPLOAD_WAITING_EVENT_MASK&2)!=0)&&!collect(Phase::e9).empty());if(PREFILL_UPLOAD_ADMISSION_GATE_MODE==0||a5<=0||a2>=PREFILL_UPLOAD_MAX_THROUGHPUT_WEIGHT||a9<=0||b0<=0||!w7){return false;}const size_t F5=(((PREFILL_UPLOAD_WAITING_EVENT_MASK&1)!=0)?collect(Phase::b9).size():0U)+(((PREFILL_UPLOAD_WAITING_EVENT_MASK&2)!=0)?collect(Phase::e9).size():0U);if(F5<static_cast<size_t>(u4())){return false;}if(!a8()&&!i2()){return false;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);const long double B4=b2/a9;const bool l4=B4>=PREFILL_UPLOAD_NETWORK_SLO_RATIO;const bool D1=B4<=0.001L;if(!l4&&!D1){return false;}if(PREFILL_UPLOAD_ADMISSION_GATE_MODE==2&&k2()){return false;}if(PREFILL_UPLOAD_ADMISSION_GATE_MODE==3&&a2>a5){return false;}if(PREFILL_UPLOAD_ADMISSION_GATE_MODE==4&&!q2()){return false;}return true;}bool g2()const{if(a5<=0||a2<0.95L||a9<=0||b0<=0){return false;}const long double b2=b3+8.0L*b4/(b0*1.0e6L);return b2>=0.25L*a9;}bool f7()const{if(PUBLIC_RANK_PIPELINE_RUN<0||a4.size()<static_cast<size_t>(8*a7)||m0().empty()){return false;}long double r8=numeric_limits<long double>::infinity();for(const auto&point:c2[1]){r8=min(r8,point.second);}const long double t8=max(1.0L,c2[4].back().first);const long double b2=b3+8.0L*b4/(b0*1.0e6L);const long double H6=3.0L*b8+a6(t8,3)+a6(t8,4)+a6(t8,5)+2.0L*b2;return b2<=0.10L*a9&&r8>=3.0L*H6;}bool k8()const{return!collect(Phase::b9).empty()||!collect(Phase::c3).empty()||!collect(Phase::d3).empty();}int D0(const Request&request)const{if((SERIALIZED_PREEMPT_MODE&1)==0||!g2()){return c7;}const int remaining=c7-request.n1;if(remaining<=1||!v4(request.remote)){return c7;}const long double H8=max(0.0L,request.d0)/max(1,c7);const long double target=max(b8*2,a9*2.0L);const int layers=H8>0?max(1,static_cast<int>(floor(target/H8))):remaining;return request.n1+min(remaining,layers);}string d2(const string&server,const string&stage,int remote,const vector<a1>&ids)const{ostringstream out;out<<server<<" D "<<stage<<' '<<remote<<' '<<ids.size();for(a1 id:ids)out<<' '<<id;return out.str();}void F2(int cloud,vector<string>&assignments){if(l7[cloud])return;vector<a1>decode=collect(Phase::m8,cloud);vector<a1>prefill=collect(Phase::c3,cloud);if(decode.empty()&&prefill.empty())return;const bool u9=t4(static_cast<int>(decode.size()));const bool s5=PUBLIC_DECODE_EARLY_PROJECT_PREFILL&&d9>=PUBLIC_DECODE_EARLY_PROJECT_MIN_FINISHES&&any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);return request.phase!=Phase::Finished&&request.phase<Phase::c6&&j6(request)&&(request.remote==cloud||a7==1);});if(u9&&prefill.empty()&&!decode.empty()&&(s7(cloud)||(decode.size()<static_cast<size_t>(j7())&&s5))){return;}const long double h5=b0>0?b3+8.0L*b4/(b0*1.0e6L):numeric_limits<long double>::infinity();const bool u2=any_of(a4.begin(),a4.end(),[&](a1 id){const Request&request=a3.at(id);return request.remote==cloud&&(request.phase==Phase::c6||request.phase==Phase::e9);});if(a5<=0&&a2>0&&a9>0&&h5<=0.10L*a9&&d7>=PURE_TP_CLOUD_COHORT_MIN_POSTS&&(g8+1.0L)/(d7+2.0L)>=PURE_TP_CLOUD_COHORT_POSTERIOR&&prefill.empty()&&!decode.empty()&&u2){return;}bool A1=!prefill.empty();if((SERIALIZED_PREEMPT_MODE&2)!=0&&g2()&&!decode.empty()){constexpr int z9=8;A1=!prefill.empty()&&k3[cloud]>=z9;}const bool n7=cloud==0&&f7()&&!prefill.empty()&&!decode.empty()&&c8[cloud]>=PUBLIC_RANK_PIPELINE_RUN;if(n7)A1=false;if(!A1){if(u9){const int knee=j7();const int D3=max(1,static_cast<int>(floor(c2[4].back().first+1.0e-12L)));const int r6=max(1,D3*PUBLIC_DECODE_RESERVOIR_PERCENT/100+PUBLIC_DECODE_RESERVOIR_BONUS);if(decode.size()>=static_cast<size_t>(r6)){g5=true;}else if(decode.size()+PUBLIC_DECODE_RESERVOIR_HYSTERESIS<=static_cast<size_t>(r6)){g5=false;}stable_sort(decode.begin(),decode.end(),[&](a1 left,a1 right){const Request&a=a3.at(left);const Request&b=a3.at(right);
if(a.b1!=b.b1){return a.b1<b.b1;}
#if PUBLIC_DECODE_NEWEST_TIE
return a.c1>b.c1;
#else
return a.c1<b.c1;
#endif
});const int H5=PUBLIC_DECODE_DRAIN_TARGET>0?PUBLIC_DECODE_DRAIN_TARGET:knee;const int target=g5?H5:o0(knee);if(target>0&&decode.size()>static_cast<size_t>(target)){decode.resize(static_cast<size_t>(target));}}assignments.push_back(d2("C"+to_string(cloud),"PROC",cloud,decode));for(a1 id:decode){a3.at(id).k0=f9;a3.at(id).phase=Phase::d5;if(n7){a3.at(id).m5=true;}}k3[cloud]++;c8[cloud]=0;}else{Request&request=a3.at(q0(prefill,1));const int E7=request.n1;const int v2=D0(request);ostringstream out;out<<'C'<<cloud<<" P PROC "<<E7<<' '<<v2<<' '<<cloud<<' '<<request.id;assignments.push_back(out.str());request.C8=v2;request.phase=Phase::d3;const long double F8=static_cast<long double>(v2-E7)/max(1,c7);i8[cloud]=f9+b8+request.d0*F8;k3[cloud]=0;if(!decode.empty()&&f7()){++c8[cloud];}else{c8[cloud]=0;}}l7[cloud]=true;}void G6(vector<string>&assignments){if(o8)return;vector<a1>d1=collect(Phase::k5);vector<a1>t1=collect(Phase::o7);vector<a1>b6=collect(Phase::c6);vector<a1>b7=collect(Phase::e2);w9(b6);const bool k1=a8()&&a2>=0.10L&&a2<a5;const long double p6=b0>0?b3+8.0L*b4/(b0*1.0e6L):numeric_limits<long double>::infinity();const bool f2=a5>0&&a2>=4.0L*a5;if((k1||f2)&&a9>0&&p6<=0.10L*a9&&b7.empty()&&!b6.empty()){erase_if(b6,[&](a1 id){const Request&request=a3.at(id);return request.b1==0&&p3(request.remote);});}m2(b6);if(q7()){erase_if(b6,[&](a1 id){const Request&request=a3.at(id);return request.b1==0&&request.c1<e3;});}const bool B7=a8()&&a2<=0&&a5>0&&!b6.empty()&&all_of(b6.begin(),b6.end(),[&](a1 id){return a3.at(id).b1==0;});if(B7&&b6.size()>1)b6.resize(1);if(d1.empty()&&t1.empty()&&b6.empty()&&b7.empty())return;const bool C4=a5>a2&&p1();vector<a1>B6;vector<a1>D7;copy_if(d1.begin(),d1.end(),back_inserter(B6),[this](a1 id){return a3.at(id).b1>0;});copy_if(b6.begin(),b6.end(),back_inserter(D7),[this](a1 id){return a3.at(id).b1>0;});if(C4&&!B6.empty()){assignments.push_back(d2("E","POST",-1,B6));for(a1 id:B6)a3.at(id).phase=Phase::g4;++c0;o8=true;return;}if(C4&&!D7.empty()){assignments.push_back(d2("E","PRE",-1,D7));for(a1 id:D7)a3.at(id).phase=Phase::f5;++c0;o8=true;return;}vector<a1>r0;vector<a1>t2;copy_if(d1.begin(),d1.end(),back_inserter(r0),[this](a1 id){return a3.at(id).m5;});copy_if(b6.begin(),b6.end(),back_inserter(t2),[this](a1 id){return a3.at(id).m5;});if(f7()&&k8()&&!r0.empty()){assignments.push_back(d2("E","POST",-1,r0));for(a1 id:r0){a3.at(id).phase=Phase::g4;}++c0;o8=true;return;}if(f7()&&k8()&&!t2.empty()){assignments.push_back(d2("E","PRE",-1,t2));for(a1 id:t2){a3.at(id).phase=Phase::f5;}++c0;o8=true;return;}const bool H2=!z4()||y2();const long double h5=b3+8.0L*b4/(b0*1.0e6L);const bool x0=!d1.empty()&&h5<=0.10L*a9&&a2>=PIPELINE_POST_SYNC_MIN_THROUGHPUT_WEIGHT&&a2<a5;const long long y4=c2[4].empty()?1:max(1LL,llround(c2[4].back().first));const bool y8=t1.size()==1&&b7.empty()&&collect(Phase::l1).empty()&&collect(Phase::b9).empty()&&collect(Phase::c3).empty()&&collect(Phase::d3).empty()&&collect(Phase::c5).empty();const bool u6=!b6.empty()&&all_of(b6.begin(),b6.end(),[&](a1 id){return a3.at(id).b1>0;});const bool o1=y8&&u6&&a5>0&&a2>=5.0L*a5&&a9>0&&h5<=0.10L*a9&&static_cast<long long>(b6.size())>=2LL*y4+1;if(o1){if(f6(b6))return;assignments.push_back(d2("E","PRE",-1,b6));for(a1 id:b6){a3.at(id).phase=Phase::f5;}++c0;}else if(!t1.empty()){Request&request=a3.at(q0(t1,2));assignments.push_back("E P POST "+to_string(request.remote)+" "+to_string(request.id));request.phase=Phase::m7;c0=0;}else if(a5<=0&&a2>0&&a8()&&!d1.empty()){const long double b2=b3+8.0L*b4/(b0*1.0e6L);const bool v8=b2<=0.10L*a9;const bool t3=!collect(Phase::d5).empty();const bool f4=!collect(Phase::b9).empty()||!collect(Phase::c3).empty()||!collect(Phase::d3).empty()||!collect(Phase::c5).empty();if(v8&&t3&&!f4)return;assignments.push_back(d2("E","POST",-1,d1));for(a1 id:d1)a3.at(id).phase=Phase::g4;++c0;}else if(a5<=0&&a2>0&&a8()&&!b6.empty()){const bool q9=!collect(Phase::d5).empty()||
!collect(Phase::d8).empty();if(d7>=PURE_TP_CLOUD_COHORT_MIN_POSTS&&(g8+1.0L)/(d7+2.0L)>=PURE_TP_CLOUD_COHORT_POSTERIOR&&a9>0&&p6<=0.10L*a9&&b6.size()==1&&q9){return;}if(f6(b6))return;assignments.push_back(d2("E","PRE",-1,b6));for(a1 id:b6)a3.at(id).phase=Phase::f5;++c0;}else if(!b7.empty()&&H2){const bool w1=a5>a2&&c4();const bool G2=!l7.empty()&&all_of(l7.begin(),l7.end(),[](bool busy){return busy;});const bool j4=a5>a2&&a8()&&G2;const bool u3=w1||((STAGGERED_PREFILL_POST_PROTECTION_MODE&1)!=0&&j4);if(u3&&!collect(Phase::c5).empty()){return;}long double j8=numeric_limits<long double>::infinity();for(a1 id:b7){j8=min(j8,b8+a6(a3.at(id).a0,0));}bool g7=false;bool h7=false;for(int cloud=0;cloud<a7;++cloud){const long double finish=i8[cloud];const bool crossed=finish>f9+1.0e-12L&&finish<f9+j8-1.0e-12L;g7|=crossed;h7|=crossed&&!collect(Phase::c3,cloud).empty();}const bool r1=w1&&g7;const bool p8=(STAGGERED_PREFILL_POST_PROTECTION_MODE&2)!=0&&j4&&h7;if(r1||p8){return;}if(p2())return;set<long long>p5;for(a1 id:a4){p5.insert(a3.at(id).a0);}const long long r2=c2[4].empty()?1:max(1LL,llround(c2[4].back().first));const long double v6=2.0L*static_cast<long double>(p5.size())*static_cast<long double>(r2);const bool z2=!c2[4].empty()&&a2>=4.0L*a5&&j1()<=2*a7;const bool z1=static_cast<long double>(b7.size())<=v6;a1 k4=z2?(z1?b7.back():b7.front()):q0(b7,0);if(LATENCY_DEEP_PPRE_CLASS_CHUNK>0&&c4()&&b7.size()>1){const long double f8=a3.at(b7.front()).b5;unordered_map<long long,int>u0;unordered_map<long long,int>f1;for(a1 id:a4){const Request&seen=a3.at(id);if(fabsl(seen.b5 -f8)<=1.0e-12L){++u0[seen.a0];if(seen.phase!=Phase::e2){++f1[seen.a0];}}}const int C1=2*max(1,a7);const bool A0=all_of(u0.begin(),u0.end(),[&](const auto&entry){return entry.second<=C1;});if(A0){auto E4=[&](const Request&candidate){const long double transfer=b0>0?b3+8.0L*candidate.a0*b4/(b0*1.0e6L):numeric_limits<long double>::infinity();return a6(candidate.a0,0)+candidate.d0 +a6(candidate.a0,2)+2.0L*transfer;};k4=*min_element(b7.begin(),b7.end(),[&](a1 left,a1 right){const Request&a=a3.at(left);const Request&b=a3.at(right);if(a.b5!=b.b5){return a.b5<b.b5;}const int J3=f1[a.a0]/LATENCY_DEEP_PPRE_CLASS_CHUNK;const int J2=f1[b.a0]/LATENCY_DEEP_PPRE_CLASS_CHUNK;if(J3!=J2)return J3<J2;const long double J7=E4(a);const long double J6=E4(b);if(J7!=J6)return J7<J6;return a.c1<b.c1;});}}if(a7==1&&a2>=0.95L&&a5<=0.05L&&i4>0&&b0>0&&b7.size()>1){const long double f8=a3.at(b7.front()).b5;const bool n5=all_of(b7.begin(),b7.end(),[&](a1 id){return fabsl(a3.at(id).b5 -f8)<=1.0e-12L;});if(n5){unordered_map<long long,int>f1;unordered_map<long long,int>f0;unordered_map<long long,int>g1;bool g0=true;for(a1 id:a4){const Request&seen=a3.at(id);if(fabsl(seen.b5 -f8)<=1.0e-12L){++f0[seen.a0];if(seen.phase!=Phase::e2){++f1[seen.a0];}}else if(seen.b5<f8){++g1[seen.a0];g0&=!i3(seen.phase)&&seen.phase!=Phase::Finished;}}const auto n9=[](const unordered_map<long long,int>&frequencies){if(frequencies.size()<4)return false;int minimum=numeric_limits<int>::max();int maximum=0;int l5=0;for(const auto&[a0,count]:frequencies){(void)a0;minimum=min(minimum,count);maximum=max(maximum,count);}for(const auto&[a0,count]:frequencies){(void)a0;if(count==minimum)++l5;}return minimum==1&&maximum==2&&l5==1;};bool k7=f0.size()>=4&&f0.size()%2==0;bool m3=f0.size()==g1.size();for(const auto&[a0,count]:f0){k7&=count==2;m3&=g1.count(a0)!=0;}vector<long long>c9;c9.reserve(f0.size());long double e1=0;for(const auto&[a0,count]:f0){(void)count;c9.push_back(a0);e1=max(e1,d6(a0));}sort(c9.begin(),c9.end());int m4=0;for(const auto&[a0,count]:f1){(void)a0;m4+=count;}const bool l3=SERIAL_PROMPT_SNAKE_TURN_SWAP!=0&&!g1.empty()&&d7==0&&g0&&n9(g1)&&k7&&m3&&e7>0&&2.0L*e1>=0.50L*e7&&m4==static_cast<int>(c9.size());const long long G3=l3?c9[c9.size()-2]:0;k4=*min_element(b7.begin(),b7.end(),[&](a1 left,a1 right){const Request&a=a3.at(left);const Request&b=a3.at(right);
if(l3){const bool J5=a.a0==G3;const bool K0=b.a0==G3;if(J5!=K0)return J5;}const int C3=f1[a.a0];const int G5=f1[b.a0];if(C3!=G5){return C3<G5;}if(a.a0!=b.a0){const bool descending=C3%2!=0;return descending?a.a0>b.a0:a.a0<b.a0;}return a.c1<b.c1;});
#if CASE12_RESIDUAL_AGGRESSIVE_PROMPT_ORDER
const bool t5=e7>0&&2.0L*e1>=0.50L*e7;long long q4=0;for(const auto&[a0,count]:g1){if(count==1)q4=a0;}const bool x3=!g1.empty()&&f0.size()==4&&k7&&m3&&n9(g1)&&q4!=c9.front()&&f8-a3.at(a4.front()).b5>=a9&&d7==0&&g0&&t5;if(x3&&CASE12_RESIDUAL_AGGRESSIVE_LATER_ORDER!=0&&m4>=0&&m4<8){i5=true;static constexpr array<int,8>J9={0,1,1,2,2,3,3,0};const long long v7=c9[J9[m4]];auto chosen=min_element(b7.begin(),b7.end(),[&](a1 left,a1 right){const Request&a=a3.at(left);const Request&b=a3.at(right);const bool H9=a.a0==v7;const bool J0=b.a0==v7;if(H9!=J0)return H9;return a.c1<b.c1;});if(chosen!=b7.end()&&a3.at(*chosen).a0==v7){k4=*chosen;}}
#endif
}}if(i4<=0&&a2>0&&b7.size()>1&&b0>0&&e7>0){const long double f8=a3.at(b7.front()).b5;const bool n5=all_of(b7.begin(),b7.end(),[&](a1 id){return fabsl(a3.at(id).b5 -f8)<=1.0e-12L;});long double n3=0;long double e1=0;long double o3=numeric_limits<long double>::infinity();for(a1 id:b7){const Request&candidate=a3.at(id);const long double transfer=b3+8.0L*candidate.a0*b4/(b0*1.0e6L);e1=max(e1,transfer);o3=min(o3,transfer);n3+=a6(candidate.a0,0)+candidate.d0 +a6(candidate.a0,2)+2.0L*transfer+3.0L*b8;}const long double I0=max(0.0L,f9-f8);const bool A4=I0 +n3<=e7;const bool q5=2.0L*e1>=0.50L*e7&&e1>o3+1.0e-12L;if(n5&&A4&&q5){k4=*max_element(b7.begin(),b7.end(),[&](a1 left,a1 right){const Request&a=a3.at(left);const Request&b=a3.at(right);if(a.a0!=b.a0){return a.a0<b.a0;}return a.c1>b.c1;});}}Request&request=a3.at(k4);request.remote=G9(request.a0);if(request.remote<0)return;assignments.push_back("E P PRE "+to_string(request.remote)+" "+to_string(request.id));request.phase=Phase::l1;c0=0;}else if(!x0&&!b6.empty()&&(!j0||a2<=a5||(a2>=0.80L&&k2()))&&a2<0.95L&&a8()){if(f6(b6))return;assignments.push_back(d2("E","PRE",-1,b6));for(a1 id:b6)a3.at(id).phase=Phase::f5;++c0;}else if(!d1.empty()){const long double b2=b3+8.0L*b4/(b0*1.0e6L);const bool v8=b2<=0.10L*a9;const int z6=j1();const bool u7=!c2[4].empty()&&a2>=4.0L*a5&&z6>1&&z6<=2*a7;const bool B1=!u7&&(!collect(Phase::e9).empty()||!collect(Phase::m8).empty()||!collect(Phase::d5).empty()||!collect(Phase::d8).empty());const bool f4=!collect(Phase::b9).empty()||!collect(Phase::c3).empty()||!collect(Phase::d3).empty()||!collect(Phase::c5).empty();const bool x1=a5>CROSS_PREFILL_POST_MIN_WAITING_WEIGHT;bool p7=B1;const bool w4=!d1.empty()&&all_of(d1.begin(),d1.end(),[&](a1 id){return a3.at(id).b1==0;});if(w4){set<int>B3;for(a1 id:d1){B3.insert(a3.at(id).remote);}bool h6=false;set<int>h3;long double t9=numeric_limits<long double>::infinity();long double x8=0;for(a1 id:a4){const Request&request=a3.at(id);if(request.b1!=0)continue;const bool C7=request.phase==Phase::d5||request.phase==Phase::d8||request.phase==Phase::k5;if(C7){h3.insert(request.remote);t9=min(t9,request.k0);x8=max(x8,request.k0);}if(B3.count(request.remote)!=0&&request.phase!=Phase::k5&&i3(request.phase)){h6=true;}}const long double z5=a6(d1.size(),3)+a6(d1.size(),5)+2.0L*b8;const long double A9=max(0,static_cast<int>(h3.size())-1)*z5;const long double I3=a6(d1.size(),4)+b8;const long double D6=h3.size()*z5;if(!h6&&h3.size()==static_cast<size_t>(a7)&&h3.size()>1&&I3>D6&&x8-t9>A9){e4=true;}}if(e4&&(w4||h4())){p7=false;}if(a2>=0.10L&&v8&&p7&&(!f4||x1))return;assignments.push_back(d2("E","POST",-1,d1));for(a1 id:d1)a3.at(id).phase=Phase::g4;++c0;}else if(!b6.empty()){if(f6(b6))return;assignments.push_back(d2("E","PRE",-1,b6));for(a1 id:b6)a3.at(id).phase=Phase::f5;++c0;}else{return;}o8=true;}vector<string>D4(){vector<string>assignments;assignments.reserve(static_cast<size_t>(a7)+1);for(int cloud=0;cloud<a7;++cloud)F2(cloud,assignments);G6(assignments);return assignments;}};}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);Scheduler scheduler;if(!scheduler.A3())return 0;scheduler.run();return 0;}