#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; int cnt; #ifdef DEBUG int a[300]; bool lt(int x, int y) { cnt++; return a[x] > a[y]; } #else bool lt(int x, int y) { cnt++; cout << "? " << x+1 << ' ' << y+1 << endl; int res; cin >> res; return res == y+1 ? 1 : 0; } #endif int main() { // cin.tie(nullptr); // ios::sync_with_stdio(false); mt19937 mt(123); #ifdef DEBUG rep(i, 300) a[i] = i; int n = 300; #else int n; cin >> n; #endif vector ord(n); rep(i, n) ord[i] = i; vector> win(n); while (ord.size() >= 2) { vector next; for (int i = 0; i + 1 < ord.size(); i += 2) { if (lt(ord[i], ord[i + 1])) { next.push_back(ord[i + 1]); win[ord[i + 1]].push_back(ord[i]); } else { next.push_back(ord[i]); win[ord[i]].push_back(ord[i + 1]); } } if (ord.size() % 2 == 1) { next.push_back(ord.back()); } ord = next; } int x = ord[0]; int second = win[x][0]; for (int i = 1; i < win[x].size(); i++) { if (lt(second, win[x][i])) { second = win[x][i]; } } cout << "! " << second+1 << endl; cerr << cnt << endl; }