#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
int com[5010];
int ask[15][5010];
int a0[5010];
int cum[15];
int col[5010];
int ans[5010];
void exploreCave(int N)
{
int n = N;
for (int i = 0; i < n; i++){
int now = i;
int idx = 0;
while (now){
if (now%2) ask[idx][i] = 1;
now /= 2;
idx++;
}
}
/*for (int i = 0; (1<<i) <= n; i++){
for (int j = 0; j < n; j++) cout << ask[i][j] << " ";
cout << "\n";
}*/
for (int i = 0; i < n; i++){
a0[i] = 0;
}
/*a0[0] = 0;
a0[1] = 0;
a0[2] = 0;
a0[3] = 0;*/
//cout << tryCombination(a0) << "\n";
for (int i = 0; i < n; i++){
int res0 = tryCombination(a0);
// res0 = i -> door i is 1
// res0 != i -> door i is 0
//cout << i << " : " << res0 << " \n";
memset(cum, 0, sizeof cum);
for (int j = 0; (1<<j) <= n; j++){
int now = tryCombination(ask[j]);
if (now != i) cum[j] = 1;
//for (int k = 0; k < n; k++) cout << ask[j][k] << " "; cout << " : ";
//cout << now << "\n";
}
int sum = 0;
for (int j = 0; (1<<j) <= n; j++){
if (res0 != i) cum[j] = 1-cum[j];
if (cum[j]) sum += (1<<j);
}
int bit = (res0 == i);
a0[sum] = bit;
for (int j = 0; (1<<j) <= n; j++){
ask[j][sum] = bit;
}
col[i] = sum;
}
for (int i = 0; i < n; i++){
ans[col[i]] = i;
}
answer(a0, ans);
}