def f(d,u) if d==u then puts ["!",d]*" " else m=(d+u)/2 puts ["?",m]*" " x=gets.to_i if x==1 then puts ["?",m+1]*" " if gets.to_i==0 then puts ["!",m]*" " return end end if x==0 then f(d,m) else f(m+1,u) end end end f(1,10**9)