def ask x, y, z @memo ||= {} return @memo[[x, y, z]] if @memo.key? [x, y, z] puts "? #{x} #{y} #{z}" $>.flush @memo[[x, y, z]] = gets.to_i end def sho x, y, z puts "! #{x} #{y} #{z}" end ans = [0] * 3 3.times do |i| ld, ud = -100, 100 until ud - ld < 3 xd, yd = ld + (ud - ld) / 3, ud - (ud - ld) / 3 ll, xx, yy, uu = 0, 0, 0, 0 q = [0, 0, 0] "lxyu".chars.each do |c| eval("q[i] = #{c}d") eval("#{c}#{c} = ask(*q)") end if ll <= xx && xx <= yy && yy <= uu ud = xd elsif ll >= xx && xx <= yy && yy <= uu ud = yd elsif ll >= xx && xx >= yy && yy <= uu ld = xd else ld = yd end end best, z = 100000, 0 ld.upto(ud) do |j| q = [0, 0, 0] q[i] = j d = ask(*q) best, z = d, j if best > d end ans[i] = z end sho *ans