#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
#include "swaps.h"
const int MAX_N = 300010;
void solve(int N, int V) {
int sz = 1;
while (sz < N) sz <<= 1;
vector<int> id(sz); iota(AI(id), 1);
random_shuffle(AI(id));
random_shuffle(AI(id));
vector<pair<int,int>> comp, ext;
auto add_cp = [&](int i, int j) {
if (max(id[i], id[j]) > N) {
ext.pb(i, j);
return;
}
schedule(id[i], id[j]);
comp.pb(i, j);
};
auto done = [&]() {
vector<int> ret = visit();
for (int j = 0;j < ret.size();++j) {
if (ret[j] == 0) {
auto [x, y] = comp[j];
DE(id[x], id[y]);
swap(id[x], id[y]);
}
}
for (auto [i, j] : ext) {
if (id[i] > N) {
swap(id[i], id[j]);
}
}
ext.clear();
comp.clear();
};
for (int d = sz/2;d > 0;d >>= 1) {
for (int i = 0;i < sz;++i) if (i&d)
add_cp(i-d, i);
done();
DE(d);
debug(AI(id));
}
DE("sort back");
for (int d = 2;d <= sz;d <<= 1) {
for (int i = 0;i < sz;i += d) {
for (int j = 1;j < d/2;++j) {
DE(i+j, i+d/2+j-1);
add_cp(i+j, i+d/2+j-1);
}
}
done();
for (int i = 0;i < sz;i += d) {
vector<int> nod {id[i]};
for (int j = 1;j < d/2;++j) {
nod.pb(id[i+j]);
nod.pb(id[i+d/2+j-1]);
}
nod.pb(id[i+d-1]);
for (int j = 0;j < d;++j)
id[i + j] = nod[j];
}
DE(d);
debug(AI(id));
}
id.resize(N);
answer(id);
}