#include using namespace std; #define rep(i, l, r) for (ll i = (l); i < (r); ++i) #define all(x) (x).begin(), (x).end() using ll = long long; using pl = pair; using vl = vector; using vvl = vector>; using vi = vector; using vvi = vector>; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") vector> hbtoid={ {0,1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14}, {15,16,17}, {18}, {19} }; vector idtoh={0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,4,5}; vector idtob={0,1,2,3,4,5,0,1,2,3,4,0,1,2,3,0,1,2,0,0}; int hbsim(string a,string b){ int ih=0; rep(i,0,a.size())if(a[i]==b[i])ih++; a+=b; sort(all(a)); int ib=-ih; rep(i,0,a.size()-1)if(a[i]==a[i+1])ib++; return hbtoid[ih][ib]; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); vector slis; string s="00000"; for(s[0]='0';s[0]<='9';s[0]++){ for(s[1]='0';s[1]<='9';s[1]++){ for(s[2]='0';s[2]<='9';s[2]++){ for(s[3]='0';s[3]<='9';s[3]++){ for(s[4]='0';s[4]<='9';s[4]++){ int a=0; rep(i,0,5){ rep(j,i+1,5)if(s[i]==s[j])a=1; } if(a==0)slis.push_back(s); } } } } } vector u(30240,true); vector> g; vector> gg; vector> h; vector nm; vector> cc; int bnow=-1; while(true){ int a=0; if(bnow==-1){ int bc=rand(); rep(i,0,u.size()){ if(u[(i+bc)%u.size()]){ a=(i+bc)%u.size(); break; } } } else a=bnow; cout< d(20); rep(i,0,30){ int a,b; cin>>a>>b; if(a==-1&&b==-1)return 0; d[hbtoid[a][b]]++; } if(d[19]==30)break; g.push_back(d); gg.push_back(d); gg[gg.size()-1][19]=0; if(gg.size()>=2&&g[g.size()-1][19]>g[g.size()-2][19]){ rep(i,0,gg.size()-1){ int id=cc[i][a]; gg[i][id]--; if(gg[i][id]==0){ rep(j,0,u.size()){ if(!u[j])continue; int id2=cc[i][j]; if(id==id2){ u[j]=false; rep(k,0,h.size()){ h[k][cc[k][j]]--; } } } } } } vector e(20); vector f(20); vector c(u.size()); rep(i,0,u.size()){ if(!u[i])continue; int id=hbsim(slis[i],slis[a]); c[i]=id; if(d[id]==0){ u[i]=false; rep(k,0,h.size()){ h[k][cc[k][i]]--; } } if(u[i]){ e[id]++; f[id]=i; } } cc.push_back(c); h.push_back(e); rep(i,0,h.size()){ if(bnow!=-1)break; rep(j,0,19){ if(h[i][j]==1){ rep(k,0,u.size()){ if(u[k]&&cc[i][k]==j){ bnow=k; break; } } } } } } }