#include "perm.h"
#include<set>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
vll to_binary(ll k) {
vll ind;
for (ll i = 60; i >= 0; i--) {
if (k & (1LL << i)) {
ind.push_back(i);
}
}
return ind;
}
std::vector<int> construct_permutation(long long k)
{
ll n = 0;
vll sol = to_binary(k);
n = sol[0] + ll(sol.size()) - 1;
ll cur = 0;
ll pos = 0;
vector<int> ans(n);
ll got = 0;
ll down = n - 1;
while (cur < sol[0]) {
while (sol.back() == got) {
ans[pos] = down;
down--;
pos++;
sol.pop_back();
}
ans[pos] = cur;
pos++;
cur++;
got++;
}
return ans;
}