#include "doll.h"
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, ccn = 0, st = 0;
ll l[200205], r[200205], pnd;
vector<int> c, x, y;
bool isl[200205];
ll cons(ll cc, ll cr) {
if (cc == 0) return -1;
if (cr == 1) return 1;
ll ci = ++ccn;
l[ci] = cons(cc>>1, cr>>1);
r[ci] = cons((cc+1)>>1, cr>>1);
return -ci;
}
void qu(ll ci, ll to) {
//cout << "v " << ci << " " << to << endl;
isl[ci] ^= 1;
if (isl[ci]) {
if (l[ci] < 0) qu(-l[ci], to);
else x[ci-1] = to;
}
else {
if (r[ci] < 0) qu(-r[ci], to);
else y[ci-1] = to;
}
}
void create_circuit(int M, vector<int> A) {
n = A.size(), m = M;
while ((1<<st) < n + 1) st++;
cons(n + 1, 1<<st);
iloop(0, m + 1) c.push_back(-1);
iloop(0, ccn) x.push_back(l[i+1]), y.push_back(r[i+1]);
/*for (auto it : x) cout << it << " ";
cout << endl;
for (auto it : y) cout << it << " ";
cout << endl;*/
for (auto it : A) qu(1, it);
qu(1, 0);
answer(c, x, y);
/*for (auto it : c) cout << it << " ";
cout << endl;
for (auto it : x) cout << it << " ";
cout << endl;
for (auto it : y) cout << it << " ";
cout << endl;*/
return;
}