def query(y) STDOUT.puts("? #{y}") STDOUT.flush gets.chomp.to_i end res = query(100) if res == 0 puts 100 exit elsif res < 0 ok = 0 ng = 100 else ok = 100 ng = 10 ** 9 + 1 end 99.times do |i| y = (ok + ng) / 2 res = query(y) if res == 0 STDOUT.puts(y + i + 1) STDOUT.flush break elsif res < 0 ng = y ok = [0, ok - 1].max else ok = [0, y - 1].max end end