#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define i_7 1000000007 #define i_5 1000000005 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; else return c+i_7; } typedef pair i_i; typedef pair l_l; ll inf=1000000000000;/*10^12*/ #define rep(i,l,r) for(ll i=l;i<=r;i++) ll max(ll a,ll b){if(ab)return b;else return a;} ////////////////////////////////////// #define koko 0 void print(int a,int b,int c,int d){ cout<s; rep(j,0,3)s.insert(a[j]); if(s.size()==4){ flag=false; } } rep(j,0,3)q[i][j]=a[j]; print(a[0],a[1],a[2],a[3]); cin>>q[i][4]>>q[i][5]; if(q[i][4]==4&&q[i][5]==0){ return 0; } } int pos=koko; rep(i,0,9999){ int b[4]; int c=i; rep(j,0,3){ b[3-j]=c%10; c/=10; } sets; rep(j,0,3)s.insert(b[j]); if(s.size()==4){ bool flag=true; rep(j,0,pos-1){ int coua=0; rep(k,0,3){ if(b[k]==q[j][k])coua++; } if(coua!=q[j][4]){ flag=false;break; } int coub=-coua; rep(k,0,3){ rep(l,0,3){ if(b[k]==q[j][l])coub++; } } if(coub!=q[j][5]){ flag=false;break; } } if(flag){ rep(j,0,3)q[pos][j]=b[j]; print(b[0],b[1],b[2],b[3]); cin>>q[pos][4]>>q[pos][5]; if(q[pos][4]==4&&q[pos][5]==0){ return 0; } pos++; } } } return 0; }