#include <bits/stdc++.h>
//#include <array>
//struct player{
// bool last_message;
// std::array<int, 4096> memory;
//};
//int precalc(int n, int m);
//bool transmit(player &player, int round, int position);
#include "mpc.h"
using namespace std;
int M, N;
int preclac(int n, int m){
M = m, N = n;
return n + m + 3;
}
bool transmit(player &player, int round, int position){
int p = (round >= position + 1 ? round - position - 1 : M + 4 - (position - round) % 16);
if(p < 0) return 0;
player.memory[p] += player.last_message;
for(int i = p; player.memory[i] >= 2; ++ i) player.memory[i] -= 2, ++ player.memory[i + 1];
int res = player.memory[p];
if(round <= position && position ^ N) player.memory[p] = 0;
return res;
}