def send_query(x, y, z) STDOUT.puts("? %d %d %d" % [x, y, z]) STDOUT.flush d = gets.to_i end lefts = [-200, -200, -200] rights = [200, 200, 200] def ternary_search_tree(left, right) loop_cnt = 55 loop_cnt.times do if yield((left * 2 + right) / 3) < yield((left + right * 2) / 3) right = (left + right * 2) / 3 else left = (left * 2 + right) / 3 end end (left + right) / 2 end ans = [0, 0, 0] 3.times do |i| l = lefts[i] r = rights[i] if i == 0 x = ternary_search_tree(l, r) { |x| send_query(x, ans[1], ans[2]) } ans[0] = x elsif i == 1 y = ternary_search_tree(l, r) { |y| send_query(ans[0], y, ans[2]) } ans[1] = y else z = ternary_search_tree(l, r) { |z| send_query(ans[0], ans[1], z) } ans[2] = z end end min_dist = Float::INFINITY best_ans = ans.dup 3.times do |i| x = ans[0] + (i - 1) 3.times do |j| y = ans[1] + (j - 1) 3.times do |k| z = ans[2] + (k - 1) end d = send_query(x, y, z) if min_dist > d min_dist = d best_ans = [x, y, z] end end end STDOUT.puts("! %d %d %d" % best_ans) STDOUT.flush