$>.sync = true def query(n) puts"? #{n}" # $_ = n >= N ? "1\n" : "0\n" # $*<<$_ !gets[?0] end ans = (1..10**9).bsearch{|i| query(i) } puts"! #{ans}"