#include <bits/stdc++.h>
using namespace std;
void send_message(vector<bool> M, vector<bool> C) {
vector<int> pos, d(31, 0);
vector<vector<bool> > all(66, vector<bool>(16, 0));
for (int i = 0; i < 31; i++) {
if (!C[i]) pos.push_back(i);
}
for (int i = 0; i < 15; i++) d[pos[i]] = pos[i + 1] - pos[i];
d[pos[15]] = pos[0] + 31 - pos[15];
vector<bool> msg;
for (bool x : M) msg.push_back(x);
msg.push_back(true);
while (msg.size() != 1025) msg.push_back(false);
for (int i = 0, cur = 0; i < 66; i++) {
for (int j = 0; j < 31; j++) {
if (!C[j]) {
if (i < d[j]) {
if (i == d[j] - 1) all[i][j] = 1;
else all[i][j] = 0;
}
else all[i][j] = msg[++cur];
}
}
}
for (int i = 0; i < 66; i++) {
vector<bool> useless = send_packet(all[i]);
}
}
vector<bool> receive_message(vector<vector<bool> > R) {
vector<int> d(31, 0), to(31, 0);
for (int i = 0; i < 31; i++) {
for (int j = 0; j < 66; j++) {
if (R[i][j]) { d[i] = j + 1; break; }
}
d[i] = min(d[i], 31);
to[i] = (i + d[i]) % 31;
}
vector<bool> vis(31, false);
for (int i = 0; i < 31; i++) {
int cnt = 1, res = to[i];
while (res != i) res = to[res], cnt++;
if (cnt == 16) {
res = to[i]; vis[i] = true;
while (!vis[res]) vis[res] = 1, res = to[res];
}
}
vector<bool> msg;
for (int i = 0; i < 66; i++) {
for (int j = 0; j < 31; j++) {
if (vis[j] && i >= d[j]) {
msg.push_back(R[i][j]);
}
}
}
while (msg.back() != true) msg.pop_back();
msg.pop_back(); return msg;
}