#include #include #include #include using namespace std; using BI = vector; BI add(const BI &a, const BI &b) { BI c(a.size()); int q = 0; for (int i = 0; i < (int)a.size(); i++) { c[i] = a[i] + b[i] + q; int base = (3 * i + 1) * (3 * i + 2) * (3 * i + 3); q = c[i] >= base; c[i] = c[i] >= base ? c[i] - base : c[i]; } return c; } BI div2(const BI &a) { BI b(a.size()); int q = 0; for (int i = (int)a.size() - 1; i >= 0; i--) { q = q * (3 * i + 1) * (3 * i + 2) * (3 * i + 3) + a[i]; b[i] = q / 2; q %= 2; } return b; } bool gr(const BI &a, const BI &b) { for (int i = (int)a.size() - 1; i >= 0; i--) { if (a[i] != b[i]) { return a[i] > b[i]; } } return false; } void find_perm(const BI &a, int n, int p[]) { vector b(n); iota(b.begin(), b.end(), 1); for (int i = 0; i < n; i++) { int t = n - 1 - i, x = t / 3, y = t % 3; int v = y == 0 ? a[x] % (3 * x + 1) : y == 1 ? a[x] / (3 * x + 1) % (3 * x + 2) : a[x] / (3 * x + 1) / (3 * x + 2); p[i] = b[v]; b.erase(b.begin() + v); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; const int L = n / 3 + 1; BI l(L), r(L); r.back() = n % 3 == 0 ? 1 : n % 3 == 1 ? n : n * (n - 1); BI one(L); one[0] = 1; while (gr(r, add(l, one))) { BI mid = div2(add(l, r)); int q[n]; find_perm(mid, n, q); cout << "?"; for (int i = 0; i < n; i++) { cout << " " << q[i]; } cout << endl; int res; cin >> res; if (res == 1) { l = mid; } else { r = mid; } } int ans[n]; find_perm(l, n, ans); cout << "!"; for (int i = 0; i < n; i++) { cout << " " << ans[i]; } cout << endl; return 0; }