#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int M[]={31,29,31,30,31,30,31,31,30,31,30,31}; vector cand; int T; pair hit(string a,string b) { int hit=0,blow=0; int x,y; FOR(x,4) FOR(y,4) if(a[x]==b[y]) { if(x==y) hit++; else blow++; } return {hit,blow}; } string best() { int a,b,c,d; int num=101010; string be; FOR(a,10) FOR(b,10) FOR(c,10) FOR(d,10) { if(a==b) continue; if(a==c) continue; if(a==d) continue; if(b==c) continue; if(b==d) continue; if(c==d) continue; string X="0000"; X[0]+=a; X[1]+=b; X[2]+=c; X[3]+=d; map,int> M; FORR(c,cand) M[hit(c,X)]++; int ma=0; FORR2(aa,bb,M) ma=max(ma,bb); if(ma>T; while(T--) { cand.clear(); FOR(i,12) { FOR(j,M[i]) { string S="0000"; S[0]+=(i+1)/10; S[1]+=(i+1)%10; S[2]+=(j+1)/10; S[3]+=(j+1)%10; if(S[0]==S[1]) continue; if(S[0]==S[2]) continue; if(S[0]==S[3]) continue; if(S[1]==S[2]) continue; if(S[1]==S[3]) continue; if(S[2]==S[3]) continue; cand.push_back(S); } } while(cand.size()>1) { string X=best(); cout<<"? "<>x>>y; vector nex; FORR(c,cand) if(hit(X,c)==make_pair(x,y)) nex.push_back(c); cand=nex; } cout<<"! "<>x; assert(x==0); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }