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