def send_query(x, y, z) STDOUT.puts("? %d %d %d" % [x, y, z]) STDOUT.flush d = gets.to_i end lefts = [-150, -150, -150] rights = [150, 150, 150] def ternary_search_tree(left, right) loop_cnt = 25 loop_cnt.times do if yield((left * 2 + right) / 3.0) < yield((left + right * 2) / 3.0) right = (left + right * 2) / 3.0 else left = (left * 2 + right) / 3.0 end end ((left + right) / 2.0).round 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.round, ans[1], ans[2]) } ans[0] = x elsif i == 1 y = ternary_search_tree(l, r) { |y| send_query(ans[0], y.round, ans[2]) } ans[1] = y else z = ternary_search_tree(l, r) { |z| send_query(ans[0], ans[1], z.round) } 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) d = send_query(x, y, z) if min_dist > d min_dist = d best_ans = [x, y, z] end end end end STDOUT.puts("! %d %d %d" % best_ans) STDOUT.flush