#include using namespace std; using pii=pair; using tii=tuple; using qii=tuple; using ll=long long; using ull=unsigned long long; using ld=long double; constexpr int INF=1e9; constexpr ll INF_ll=1e18; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define replr(i,l,r) for (int i=(int)(l);i<(int)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((int)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a(now-start).count(); return ms; } int get_ms_all_program(){ auto now=chrono::system_clock::now(); int ms=chrono::duration_cast(now-program_start).count(); return ms; } } mt19937 mt; uint32_t rand_int(uint32_t r){ //[0,r) assert(r!=0); return ((uint64_t)mt()*r)>>32; } int rand_int(int l,int r){ //[l,r) assert(l T get_random_element(const vector &v){ assert(!v.empty()); return v[rand_int(len(v))]; } template void add(vector &a,vector b){ for(auto i:b) a.push_back(i); } constexpr int N=30,K=5; vector C; array last_vis; int vis_cnt=0; pii get_hb(const string &x,const string &y){ //TODO int h=0,b=0; vis_cnt++; rep(k,K){ last_vis[x[k]-'0']=vis_cnt; } rep(k,K){ if(x[k]==y[k]) h++; else if(last_vis[y[k]-'0']==vis_cnt) b++; } return {h,b}; } namespace Communication{ vector S; vector finished; void init(){ S.resize(N); finished.resize(N,false); auto c=C; shuffle(all(c),mt); rep(i,N){ S[i]=c[i]; cerr << "ans:" << S[i] << '\n'; } cerr << '\n'; } int turn=0,finished_cnt=0; vector query(string q){ turn++; assert(len(q)==K); vector ret(N); #ifdef LOCAL rep(i,N){ if(S[i]==q||finished[i]){ ret[i]={5,0}; if(!finished[i]) finished_cnt++; finished[i]=true; continue; } int h=0,b=0; rep(k,K){ if(S[i][k]==q[k]) h++; } rep(k,K){ rep(l,K){ if(k==l) continue; if(S[i][k]==q[l]) b++; } } ret[i]={h,b}; } sort(all(ret)); #else cout << q << '\n'; cout.flush(); finished_cnt=0; rep(i,N){ int h,b; cin >> h >> b; if(h==K&&b==0) finished_cnt++; ret[i]={h,b}; } #endif if(ret.front()==pii{K,0}){ cerr << "turn:" << turn << '\n'; exit(0); } if(ret.front()==pii{-1,-1}) assert(0); return ret; } }; namespace Solver{ string get_best_query(const vector &candidate){ string best_str; int best_size=-INF; for(const auto &x:C){ map mp; for(const auto &y:candidate){ mp[get_hb(x,y)]++; } if(chmax(best_size,len(mp))){ best_str=x; } } return best_str; } void solve(){ auto c=C; constexpr int X=200; while(true){ string str=get_random_element(c); if(len(c) hb=Communication::query(str); set st(all(hb)); st.erase({5,0}); vector new_c; for(const auto &x:c){ if(st.contains(get_hb(str,x))){ new_c.push_back(x); } } int diff=len(c)-len(new_c); c=new_c; cerr << len(c) << endl; if(diff==0&&len(c)