//#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; 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]++; 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 = lower_bound(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()); 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; } 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(unrevealed.empty() && myhandcy >= U.size() && ophandcy >= U.size()){ Hand res; res.fill(0); REP(i,M) res[i] = X[i] - U[myhandcy][i] - U[ophandcy][i]; 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; } } rec(s == "TURN"); } } int main(){ cin.tie(0)->sync_with_stdio(0); testcase(); return 0; }