#ifdef NACHIA #define _GLIBCXX_DEBUG #else // disable assert #define NDEBUG #endif #include #include #include #include #include using namespace std; using ll = long long; const ll INF = 1ll << 60; #define REP(i,n) for(ll i=0; i using V = vector; template void chmax(A& l, const B& r){ if(l < r) l = r; } template void chmin(A& l, const B& r){ if(r < l) l = r; } using Hand = array; const bool dbg = 0; void testcase(){ ll id, N, M; cin >> id >> N >> M; V A(N); REP(i,N) cin >> A[i]; sort(A.begin(), A.end()); Hand myhand; myhand.fill(0); for(auto a : A) myhand[a-1]++; V U; { V ft(N+M-1); for(ll i=M-1; i i+1){ ok = 0; break; } if(ok) U.push_back(Q); } while(next_permutation(ft.begin(), ft.end())); } ll myhandid = find(U.begin(), U.end(), myhand) - U.begin(); ll myhandcy = 1; ll ophandid = 0; ll ophandcy = 1; //cout << U.size() << endl; V X(M); V unrevealed; REP(i,M) unrevealed.push_back(i); sort(unrevealed.begin(), unrevealed.end()); exit(0); auto outputhand = [&](Hand hand) -> void { REP(i,M) REP(t,hand[i]) cout << " " << (i+1); }; auto B = U; auto rec = [&](bool ismyturn) -> void { string x; cin >> x; if(x[0] == 'G'){ string x; cin >> x >> x; } if(x[0] == 'C'){ ll x, k; cin >> x >> k; x--; X[x] = k; ll pt = x, ptin = M; if(unrevealed.size()){ pt = find(unrevealed.begin(), unrevealed.end(), x) - unrevealed.begin(); ptin = unrevealed.size(); } if(!ismyturn){ ophandid += ophandcy * pt; ophandcy *= ptin; } if(unrevealed.size()){ unrevealed.erase(find(unrevealed.begin(), unrevealed.end(), x)); sort(unrevealed.begin(), unrevealed.end()); } } }; while(1){ string s; cin >> s; if(s == "END") break; if(s == "TURN"){ if(dbg){ cout << "my turn" << endl; } if(dbg){ cout << " unrevealed.size() = " << unrevealed.size() << endl; } if(dbg){ cout << " U.size() = " << U.size() << endl; } if(dbg){ cout << " myhand = " << myhandid << " / " << myhandcy << endl; } if(dbg){ cout << " ophand = " << ophandid << " / " << ophandcy << endl; } if(unrevealed.empty() && myhandcy >= U.size() && ophandcy >= U.size()){ Hand res; res.fill(0); REP(i,M) res[i] = X[i] - U[myhandid][i] - U[ophandid][i]; if(dbg){ cout << "Guessing : "; } if(dbg){ cout << " X = "; for(auto a : X){ cout << (int)a << " "; } cout << endl; } if(dbg){ cout << " myhand = "; for(auto a : U[myhandid]){ cout << (int)a << " "; } cout << endl; } if(dbg){ cout << " ophand = "; for(auto a : U[ophandid]){ cout << (int)a << " "; } cout << endl; } cout << "GUESS"; outputhand(res); cout << endl; } else if(unrevealed.size()){ ll h = (myhandid / myhandcy) % unrevealed.size(); cout << "ASK " << (unrevealed[h] + 1) << endl; myhandcy *= unrevealed.size(); } else { ll h = (myhandid / myhandcy) % M; cout << "ASK " << (h + 1) << endl; myhandcy *= M; } } else { if(dbg){ cout << "not my turn" << endl; } if(dbg){ cout << " unrevealed.size() = " << unrevealed.size() << endl; } if(dbg){ cout << " U.size() = " << U.size() << endl; } if(dbg){ cout << " myhand = " << myhandid << " / " << myhandcy << endl; } if(dbg){ cout << " ophand = " << ophandid << " / " << ophandcy << endl; } } rec(s == "TURN"); } } int main(){ cin.tie(0)->sync_with_stdio(0); testcase(); return 0; }