#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAXN 13
#define MAX_MASK 8192
#define setbit(x, i) ((x) | (1 << (i)))
#define resetbit(x, i) ((x) & (~(1 << (i))))
int next[MAX_MASK][MAXN]; /// next[bitmask][cur] = next lis mask when the current lis mask is bitmask and cur is added to the end
void Generate(){
int i, cur, res, bitmask;
memset(next
, -1, sizeof(next
));
for (bitmask = 0; bitmask < MAX_MASK; bitmask++){
for (cur = 0; cur < MAXN; cur++){
if (bitmask == 0) next[bitmask][cur] = 1 << cur;
else{
res = setbit(bitmask, cur);
for (i = cur + 1; i < MAXN; i++){ /// Find the smallest number (if there are any) with a set bit greater than cur and reset it
if (bitmask & (1 << i)){
res = resetbit(res, i);
break;
}
}
next[bitmask][cur] = res;
}
}
}
}
int main(){
Generate();
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4KCiNkZWZpbmUgTUFYTiAxMwojZGVmaW5lIE1BWF9NQVNLIDgxOTIKI2RlZmluZSBzZXRiaXQoeCwgaSkgKCh4KSB8ICgxIDw8IChpKSkpCiNkZWZpbmUgcmVzZXRiaXQoeCwgaSkgKCh4KSAmICh+KDEgPDwgKGkpKSkpCgppbnQgbmV4dFtNQVhfTUFTS11bTUFYTl07IC8vLyBuZXh0W2JpdG1hc2tdW2N1cl0gPSBuZXh0IGxpcyBtYXNrIHdoZW4gdGhlIGN1cnJlbnQgbGlzIG1hc2sgaXMgYml0bWFzayBhbmQgY3VyIGlzIGFkZGVkIHRvIHRoZSBlbmQKCnZvaWQgR2VuZXJhdGUoKXsKICAgIGludCBpLCBjdXIsIHJlcywgYml0bWFzazsKICAgIG1lbXNldChuZXh0LCAtMSwgc2l6ZW9mKG5leHQpKTsKCiAgICBmb3IgKGJpdG1hc2sgPSAwOyBiaXRtYXNrIDwgTUFYX01BU0s7IGJpdG1hc2srKyl7CiAgICAgICAgZm9yIChjdXIgPSAwOyBjdXIgPCBNQVhOOyBjdXIrKyl7CiAgICAgICAgICAgIGlmIChiaXRtYXNrID09IDApIG5leHRbYml0bWFza11bY3VyXSA9IDEgPDwgY3VyOwogICAgICAgICAgICBlbHNlewogICAgICAgICAgICAgICAgcmVzID0gc2V0Yml0KGJpdG1hc2ssIGN1cik7CiAgICAgICAgICAgICAgICBmb3IgKGkgPSBjdXIgKyAxOyBpIDwgTUFYTjsgaSsrKXsgLy8vIEZpbmQgdGhlIHNtYWxsZXN0IG51bWJlciAoaWYgdGhlcmUgYXJlIGFueSkgd2l0aCBhIHNldCBiaXQgZ3JlYXRlciB0aGFuIGN1ciBhbmQgcmVzZXQgaXQKICAgICAgICAgICAgICAgICAgICBpZiAoYml0bWFzayAmICgxIDw8IGkpKXsKICAgICAgICAgICAgICAgICAgICAgICAgcmVzID0gcmVzZXRiaXQocmVzLCBpKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbmV4dFtiaXRtYXNrXVtjdXJdID0gcmVzOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpewogICAgR2VuZXJhdGUoKTsKfQo=