//
bool query(int);
void modify(int,bool);
bool WereYouLast(int n,int m) {
if (m == 10) {
int pos = 0;
for (int i = 1; i <= m; i++) {
pos = (pos<<1)|query(i);
}
++pos;
if (pos == n) return 1;
for (int i = m; i >= 1; i--) {
modify(i, pos&1);
pos >>= 1;
}
return 0;
}
int k = __lg(n);
int kk = 5;
int pos = 0;
for (int i = 1; i <= kk; i++) {
if (query(i)) {
pos = pos | (1 << (i-1));
}
}
pos ++;
if (pos == (1<<kk)) return 1;
if (query(kk+pos)) {
modify(kk+pos, 0);
int _p = pos;
for (int i = 1; i <= kk; i++) {
modify(i, _p&1);
_p >>= 1;
}
} else {
if (pos == k) {
for (int i = 1; i <= kk; i++) {
modify(i, 1);
}
return 0;
}
modify(kk+pos, 1);
for (int i = 1; i <= kk; i++) {
modify(i, 0);
}
}
return 0;
}