#include
#include
#include
std::vector _seen(1);
bool seen(size_t v) {
if (v < _seen.size()) {
return _seen[v];
} else {
return false;
}
}
void see(size_t v) {
while (v >= _seen.size()) {
_seen.resize(2 * _seen.size());
}
_seen[v] = true;
}
std::vector around(1);
size_t find(size_t p, size_t x) {
if (!seen(x)) {
return x;
}
size_t nb = 1;
for (size_t b = 1;; b*=2) {
if ((p & b)==0) {
if (around.size() == nb) {
around.resize(2 * around.size());
}
for (size_t k = 0; k