def get(var) c = 60.times.map do puts "? #{var}" read_line.to_i end.to_a.tally c.keys.max_by { |k| c[k] } end def add(v0, v1, v2, expect) while true puts "+ #{v0} #{v1} #{v2}" res = read_line.to_i if res != 0 exit 1 end break if get(v2) == expect end end x = get("A") y = get("B") vars = ["A", "B", "C"] # cur, buf, ans ans = 0 if y % 2 == 1 add("A", "C", "B", x) ans += x vars = ["A", "C", "B"] end y >>= 1 while y > 0 add(vars[0], vars[0], vars[1], x * 2) x *= 2 if y % 2 == 1 add(vars[1], vars[2], vars[0], ans + x) ans += x vars = [vars[1], vars[2], vars[0]] else vars.swap(0, 1) end y >>= 1 end puts "! #{vars[2]}"