#include <bits/stdc++.h>
#include "mpc.h"
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define rz resize
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct player{
bool last_message;
array<int, 4096> memory;
};
int precalc(int n, int m);
bool transmit(player &player, int round, int position);
int N, M;
int precalc(int n, int m) {
N = n, M = m;
return n + m + 3;
}
bool transmit(player &player, int round, int position) {
int p = round - position - 1, t = player.last_message;
if (p < 0) {
if (p >= -8) p = p + M + 4;
else p = p + M + 19;
}
if (p < 0) return 0;
int i = p;
for ( ; player.memory[i]; ++i) player.memory[i] = 0;
player.memory[i] = 1;
int u = player.memory[p];
if (position < N) player.memory[p] = 0;
return u;
}