#include #include #include using namespace std; int N; vector cand; int ask(int x, int y) { if (x > N) return y; if (y > N) return x; cout << "? " << x << ' ' << y << endl; int res; cin >> res; return res; } int solve(vector v) { if (v.size() == 1) return v[0]; if (v.size() % 2 == 1) { int cnt = 1; while (find(v.begin(), v.end(), cnt) != v.end()) ++cnt; v.push_back(cnt); } vector pv; for (int i = 0; i < v.size(); i += 2) { int res = ask(v[i], v[i + 1]); if (res == v[i]) pv.push_back(v[i]); else pv.push_back(v[i + 1]); } int ans = solve(pv); cand.push_back(v[(find(v.begin(), v.end(), ans) - v.begin()) ^ 1]); return ans; } int main() { cin >> N; vector v; for (int i = 1; i <= N; ++i) { v.push_back(i); } solve(v); sort(cand.begin(), cand.end()); cand.erase(unique(cand.begin(), cand.end()), cand.end()); int cur = 0; for (int i = 1; i < cand.size(); ++i) { int res = ask(cand[cur], cand[i]); if (res == cand[i]) cur = i; } cout << "! " << cand[cur] << endl; return 0; }