#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int N, L, R;
int cnt;
string s;
int ans;
} // namespace
void InitA(int N, int L, int R) {
// send R, receive R vals
::N = N;
::L = L;
::R = R;
cnt = 0;
const int w = bit_width(unsigned(N));
for (int i = w - 1; i >= 0; --i) {
SendA(R & 1 << i);
}
}
void ReceiveA(bool x) {
cnt++;
s.push_back(x ? '1' : '0');
if (cnt == R) {
s.push_back('1');
for (int i = L; i < R + 1; ++i) {
if (s[i] == '1') {
ans = i;
break;
}
}
}
}
int Answer() {
return ans;
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int N;
int w;
vector<int> p;
int cnt;
string s;
} // namespace
void InitB(int N, std::vector<int> P) {
::N = N;
p = P;
w = bit_width(unsigned(N));
cnt = 0;
}
void ReceiveB(bool y) {
cnt++;
s.push_back(y ? '1' : '0');
if (cnt == w) {
int r = stoi(s, nullptr, 2);
int min = numeric_limits<int>::max();
vector<bool> sen;
for (int i = r; i >= 0; --i) {
if (i != r) {
sen.push_back(p[i] < min);
}
if (p[i] < min) {
min = p[i];
}
}
reverse(sen.begin(), sen.end());
for (auto i : sen) {
SendB(i);
}
}
}