min = 1 max = 10**9 while max - min != 1 puts "? #{(max + min)/2}" STDOUT.flush ans = gets.to_i case ans when 0 max = (max + min)/2 - 1 when 1 min = (max + min)/2 end end puts "? #{max}" STDOUT.flush ans = gets.to_i case ans when 0 puts "! #{min}" when 1 puts "! #{max}" end