#include<bits/stdc++.h>
#include "grader.cpp"
// #include "mpc.h"
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=c=='-'?-1:f,c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
int n,m;
int precalc(int n,int m) {
srand(time(0));
::n=n,::m=m;
return n+m+4;
}
int calc(int pos,int round) {
int res=round-pos-1;
if(res<0) res+=m+11;
if(res>=0) return res;
return -1;
}
bool transmit(player &player,int round,int pos) {
int p=calc(pos-1,round-1);
if(p!=-1) {
player.memory[p]+=player.last_message;
for(int i=p;i<m+__lg(n)+1;i++) {
if(player.memory[i]>1) player.memory[i+1]++,player.memory[i]-=2;
else break;
}
}
p=calc(pos,round);
if(p==-1) return 0;
// fprintf(stderr,"pos=%d round=%d trans=%d\n",pos,round,p);
// for(int i=0;i<20;i++) fprintf(stderr,"%d",player.memory[i]);
// fprintf(stderr,"\n");
int v=player.memory[p];
if(pos!=n) player.memory[p]=0;
return v;
}