#include "integer.h"
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
unsigned xrand() {
static unsigned x = 314159265, y = 358979323, z = 846264338, w = 327950288;
unsigned t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
}
vector<int> findPermutation(int N) {
for (int i = 0; i < N; ++i) operate(i);
vector<int> is(N);
// for (int i = 0; i < N; ++i) is[i] = i;
for (int i = 0; i < N; ++i) swap(is[xrand() % (i + 1)], is[i] = i);
// cerr<<"is = "<<is<<endl;
int cnt = 0;
vector<int> P(N, -1), invP(N, -1);
for (int hi = 0; ; ++hi) {
vector<int> is0, is1;
for (const int i : is) ((~P[i]) ? is1 : is0).push_back(i);
int bef = N + __builtin_popcount(hi);
int k = N + __builtin_ctz(~hi);
for (const int i : is0) {
const int res = operate(i);
if (res - bef != 1) {
P[i] = ((res - bef) + k - 1);
invP[P[i]] = i;
// cerr<<"hi = "<<hi<<", P = "<<P<<endl;
if (++cnt == N) {
cerr<<"hi = "<<hi<<", P = "<<P<<endl;
return P;
}
k = P[i];
}
bef = res;
}
for (const int i : is1) operate(i);
operate(invP[0]);
}
return P;
}