l = 10 r = 1000000001 c = 0 loop{ y = (l + r) / 2 puts "? #{y}" STDOUT.flush ans = gets.to_i 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 c += 1 }