STDOUT.sync = true N = gets.to_i products = [] N.times do |i| a, b = [i, (i + 1) % N].minmax puts "? #{a} #{b}" x = gets.to_i products << x end digit_candidates = Array.new(N) { [true] * 10 } digit_candidates[-1][0] = false N.times do N.times do |i| 10.times do |a| if (0 ... 10).all? { |b| products[i] != a * b } digit_candidates[i][a] = false end end if digit_candidates[i].count(true) == 1 x = (0 ... 10).find { |x| digit_candidates[i][x] } if x != 0 ys = [false] * 10 ys[products[i] / x] = true digit_candidates[(i + 1) % N] = ys end end end end if digit_candidates.all? { |c| c.count(true) == 1 } ans = "" (0 ... N).reverse_each do |i| x = (0 ... 10).find { |x| digit_candidates[i][x] } ans << x end puts "! #{ans}" else puts "! -1" end