#include using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; const int MAXN = 100000; struct qpair{ int ai, aj, i, j; }; bool comp(qpair p1, qpair p2){ return min(p1.ai, p1.aj) < min(p2.ai, p2.aj); } int n; bool frozen[MAXN] = {0}; int A[MAXN] = {0}; vector pairs; vector pairs2; pii ask(int i, int j){ cout << "? " << i+1 << " " << j+1 << "\n"; fflush(stdout); pii res; cin >> res.first >> res.second; return res; } void freeze(int i, int x){ A[i] = x; frozen[i] = 1; } int other(qpair p, int x, int y){ if(min(x,y) == min(p.ai,p.aj) && max(x,y) == max(p.ai,p.aj))return -1; if(x == y){ if(p.ai != x)return p.ai; return p.aj; } if(x != p.ai && x != p.aj){ if(y == p.ai)return p.aj; return p.ai; } if(x == p.ai)return p.aj; return p.ai; } void ask_pair(qpair p1, qpair p2){ pii res = ask(p1.i, p2.i); int x = res.first; int y = res.second; int other1 = other(p1, x, y); int other2 = other(p2, x, y); if(other1 == -1){ other1 = p2.ai; if(p2.ai == other2)other1 = p2.aj; } if(other2 == -1){ other2 = p1.ai; if(p1.ai == other1)other2 = p1.aj; } if(x == y){ freeze(p1.i, x); freeze(p2.i, x); freeze(p1.j, other1); freeze(p2.j, other2); } else{ if(min(p1.ai, p1.aj) != min(p2.ai, p2.aj) || max(p1.ai, p1.aj) != max(p2.ai, p2.aj)){ freeze(p1.j, other1); freeze(p2.j, other2); frozen[p1.i] = 0; frozen[p2.i] = 0; pairs2.push_back({x, y, p1.i, p2.i}); } else{ pairs2.push_back({x, y, p1.i, p2.i}); pairs2.push_back({x, y, p1.j, p2.j}); } } } void end_game(qpair p){ if(p.ai == p.aj){ freeze(p.i, p.ai); freeze(p.j, p.aj); } else{ for(int k = 0; k < n; k++){ if(A[k] == p.ai && k != p.i && k != p.j){ vi ind = {k, p.i, p.j}; while(1){ int a = rand()%2; int b = a + rand()%2 + 1; if(b == 3)b--; pii q = ask(ind[a], ind[b]); if(q.first == q.second){ int c = 0; if(a == c)c = 1; if(b == c)c = 2; freeze(ind[a], p.ai); freeze(ind[b], p.ai); freeze(ind[c], p.aj); return; } } } } } } int main() { cin >> n; for(int c1 = 0; c1 < n; c1 += 2){ pii p = ask(c1,c1+1); int a = p.first; int b = p.second; if(a == b){ freeze(c1, a); freeze(c1+1, a); } else{ pairs.push_back({a, b, c1, c1+1}); } } sort(all(pairs), comp); for(int c1 = 0; c1 < sz(pairs)-1; c1 += 2){ ask_pair(pairs[c1], pairs[c1+1]); } if(sz(pairs)%2 == 1){ pairs2.push_back(pairs.back()); } while(sz(pairs2) > 1){ qpair p1 = pairs2.back(); pairs2.pop_back(); qpair p2 = pairs2.back(); pairs2.pop_back(); ask_pair(p1,p2); } end_game(pairs2[0]); cout << "! "; for(int c1 = 0; c1 < n; c1++){ cout << A[c1] << " "; }cout << "\n"; return 0; }