#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
void exploreCave(int n){
vector<int> id(n, 0);
vector<int> pos(n, 0);
vector<bool> vis(n, 0);
for(int i=0; i<n; i++){
int x=0;
if(tryCombination(id.data())==i){
// id[i]=1;
x=1;
}
int l=0, r=n-1;
while(l<r){
int mid=(l+r)/2;
vector<int> ask(n, 0);
for(int j=0; j<n; j++){
if(!vis[j])ask[j]=x;
else ask[j]=id[j];
}
for(int j=mid+1; j<=r; j++)if(!vis[j])ask[j]=1-x;
if(tryCombination(ask.data())==i){
// pos not in this region
l=mid+1;
}
else r=mid;
}
id[l]=x;
vis[l]=1;
pos[l]=i;
}
//for(auto e:id)cout << e << ' ';cout << '\n';
//for(auto e:pos)cout << e << ' ';cout << '\n';
answer(id.data(), pos.data());
}
/*
4
1 1 1 0
3 1 0 2
*/