#include "message.h"
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e5 + 7;
bool Check_bit(int u, int v)
{
return (u >> v) & 1;
}
vector<bool> all(bool tt)
{
vector<bool> res;
for (int i = 0; i < 31; i++)
res.push_back(tt);
return res;
}
void send_message(std::vector<bool> M, std::vector<bool> C)
{
int val = M.back() ^ 1;
while (M.size() < 1025)
M.push_back(val);
vector<int> vt;
for (int j = 0; j < C.size(); j++)
{
C[j] = !C[j];
if (!C[j])
continue;
vt.push_back(j);
}
// cerr << "VT ";
// for (int i : vt)
// cerr << i << " ";
// cerr << '\n';
vector<vector<bool>> res;
for (int i = 1; i <= 66; i++)
res.push_back(C);
int ctr = 0;
for (int i = 0; i < vt.size(); i++)
{
int dis = (vt[(i + 1) % vt.size()] - vt[i] + 31) % 31;
//cerr << "COL " << vt[i] << " " << dis << '\n';
for (int j = 0; j < 66; j++)
{
if (j < dis)
res[j][vt[i]] = (j + 1) == dis;
else
res[j][vt[i]] = M[ctr++];
}
}
for (int i = 0; i < 66; i++)
send_packet(res[i]);
}
int ctr[40];
vector<int> DFS(int j)
{
int stt = j;
vector<int> res;
while (res.size() <= 16)
{
if (stt == j && res.size())
break;
res.push_back(stt);
stt = (stt + ctr[stt]) % 31;
}
return res;
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R)
{
for (int i = 0; i < 31; i++)
{
for (int j = 0; j < R.size(); j++)
{
ctr[i]++;
if (R[j][i] == 1)
break;
}
}
vector<int> vt;
for (int i = 0; i < 31; i++)
{
vt = DFS(i);
if (vt.size() == 16)
break;
}
// cerr << "VT ";
// for (int i : vt)
// cerr << i << " ";
// cerr << '\n';
vector<bool> ans;
for (int i = 0; i < 16; i++)
{
int stt = vt[i];
for (int j = ctr[stt]; j < 66; j++)
ans.push_back(R[j][stt]);
}
int tmp = ans.back();
while (ans.back() == tmp)
ans.pop_back();
return ans;
}