#include struct random : std::mt19937 { using std::mt19937::mt19937; using std::mt19937::operator(); static int64_t gen_seed() { return std::chrono::steady_clock::now().time_since_epoch().count(); } random() : std::mt19937(gen_seed()) {} template auto operator()(Int a, Int b) -> std::enable_if_t, Int> { return std::uniform_int_distribution(a, b)(*this); } template auto operator()(Real a, Real b) -> std::enable_if_t, Real> { return std::uniform_real_distribution(a, b)(*this); } } rng; #pragma region my_template struct Rep { struct I { int i; void operator++() { ++i; } int operator*() const { return i; } bool operator!=(I o) const { return i < *o; } }; const int l_, r_; Rep(int l, int r) : l_(l), r_(r) {} Rep(int n) : Rep(0, n) {} I begin() const { return {l_}; } I end() const { return {r_}; } }; struct Per { struct I { int i; void operator++() { --i; } int operator*() const { return i; } bool operator!=(I o) const { return i > *o; } }; const int l_, r_; Per(int l, int r) : l_(l), r_(r) {} Per(int n) : Per(0, n) {} I begin() const { return {r_ - 1}; } I end() const { return {l_ - 1}; } }; template struct Fix : private F { Fix(F f) : F(f) {} template decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; template T scan() { T res; std::cin >> res; return res; } template bool chmin(T& a, U&& b) { return b < a ? a = std::forward(b), true : false; } template bool chmax(T& a, U&& b) { return a < b ? a = std::forward(b), true : false; } #ifndef LOCAL #define DUMP(...) void(0) template constexpr int OjLocal = OnlineJudge; #endif using namespace std; #define ALL(c) begin(c), end(c) #pragma endregion int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int n = scan(); int num_queries = 0; auto query = [&](int i, int j) -> array { assert(0 <= i), assert(i < n * (n - 1)); assert(0 <= j), assert(j < n * (n - 1)); ++num_queries; assert(num_queries <= n * (n - 1) / 2 * 3); cout << "? " << i + 1 << ' ' << j + 1 << endl; array res; if (OjLocal<0, 1>) { static vector ans; if (empty(ans)) { ans.resize(n * (n - 1)); iota(ALL(ans), n); shuffle(ALL(ans), rng); DUMP(ans); } res[0] = ans[i] / n - ans[j] / n; res[1] = ans[i] % n - ans[j] % n; sort(ALL(res)); } else { res = {scan(), scan()}; } assert(is_sorted(ALL(res))); return res; }; map, int> mp; for (int j : Rep(n, n * n)) { map cnt; for (int i : Rep(n, n * n)) if (i != j) { ++cnt[i / n - j / n]; ++cnt[i % n - j % n]; } mp[cnt] = j; } assert(int(size(mp)) == n * (n - 1)); vector> res(n * (n - 1)); map cnt; for (int i : Rep(1, n * (n - 1))) { res[i] = query(i, 0); for (int z : Rep(2)) ++cnt[res[i][z]]; } assert(mp.count(cnt)); vector ans(n * (n - 1)); ans[0] = mp[cnt]; vector> pre(n * n); for (int x : Rep(n, n * n)) { pre[x][0] = x / n - ans[0] / n; pre[x][1] = x % n - ans[0] % n; sort(ALL(pre[x])); } vector> pos(n * n); pos[ans[0]] = {0}; for (int i : Rep(1, n * (n - 1))) { for (int x : Rep(n, n * n)) if (x != ans[0] and res[i] == pre[x]) { pos[x].push_back(i); } } DUMP(pos); int off = -1; for (int x : Rep(n, n * n)) if (size(pos[x]) == 1) { ans[pos[x][0]] = x; if (x != ans[0] and x / n - ans[0] / n != x % n - ans[0] % n) off = x; } DUMP(off); int pos_off = find(ALL(ans), off) - begin(ans); assert(pos_off < n * (n - 1)); for (int x : Rep(n, n * n)) if (size(pos[x]) == 2) { bool first = true; for (int i : pos[x]) { array expected; expected[0] = x / n - off / n; expected[1] = x % n - off % n; sort(ALL(expected)); if (not exchange(first, false) or query(i, pos_off) == expected) { ans[i] = x; for (int y : Rep(x + 1, n * n)) if (pos[y] == pos[x]) { int other = pos[x][0] ^ pos[x][1] ^ i; ans[other] = y; pos[y].clear(); break; } break; } } } cout << '!'; for (auto&& e : ans) cout << ' ' << e; cout << endl; }