#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];
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;
}
for (int i = 0; i < n; i++){
int res0 = tryCombination(a0);
memset(cum, 0, sizeof cum);
for (int j = 0; (1<<j) <= n; j++){
int now = tryCombination(ask[j]);
if (now) cum[j] = 1;
}
if (res0 == i) for (int j = 0; (1<<j) <= n; j++) cum[j] = 1-cum[j];
int num = 0;
for (int j = 0; (1<<j) <= n; j++){
if (cum[j]) num += (1<<j);
}
if (res0 != i) a0[num] = 1;
col[i] = num;
}
answer(a0, col);
}