l = 9 r = 1000000001 c = 0 loop{ y = (l + r) / 2 puts "? #{y}" STDOUT.flush ans = gets.to_i c += 1 if ans == 0 puts "! #{y + c}" STDOUT.flush break elsif ans > 0 l = y else r = y end r = [r - 1,0].max l = [l - 1,0].max }