int encode (int n, int x, int y) {
static int cnt = 0;
static int tbl[1000];
if (cnt == 0){
for (int i = 0; i < (1<<12); i++){
if (__builtin_popcount(i) == 6){
tbl[++cnt] = i;
if (cnt == 920) break;
}
}
}
int xx = tbl[x], yy = tbl[y];
for (int i = 0; i < 12; i++){
if (((xx >> i) & 1) == 1 && ((yy>>i)&1) == 0){
return i + 1;
}
}
return (x + y) % 2;
}
int decode (int n, int q, int h) {
static int cnt = 0;
static int tbl[1000];
if (cnt == 0){
for (int i = 0; i < (1<<12); i++){
if (__builtin_popcount(i) == 6){
tbl[++cnt] = i;
if (cnt == 920) break;
}
}
}
int num = tbl[q];
--h;
return (num>>h)&1;
}