function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // Swap elements
}
}
function merge(arr1, arr2) {
const merged = [];
let i = 0;
let j = 0;
while (i < arr1.length || j < arr2.length) {
if (Math.random() < 0.5 && i < arr1.length) {
merged.push(arr1[i]);
i++;
} else if (j < arr2.length) {
merged.push(arr2[j]);
j++;
}
}
return merged;
}
function f(n) {
const zoos = [0, 1, 10];
const zoo = [];
const result = [];
for (let i = 0; i < 12; i++) {
if ((1 << i) & n) {
if (zoos.includes(i)) {
zoo.push(i);
} else {
result.push(i);
}
}
}
shuffleArray(result);
return(merge(result, zoo).join(''));
}
function g(s) {
let r = 0;
let i = 0;
while (i < s.length) {
if (i < s.length - 1
&& ['10', '11'].includes(s[i] + s[i+1])) {
r += 1 << Number(s[i] + s[i+1]);
i += 1;
} else {
r += 1 << Number(s[i]);
}
i += 1;
}
return r;
}
const n = 1355
print(f(n));
print(g(f(n)));
CmZ1bmN0aW9uIHNodWZmbGVBcnJheShhcnJheSkgewogIGZvciAobGV0IGkgPSBhcnJheS5sZW5ndGggLSAxOyBpID4gMDsgaS0tKSB7CiAgICBjb25zdCBqID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogKGkgKyAxKSk7CiAgICBbYXJyYXlbaV0sIGFycmF5W2pdXSA9IFthcnJheVtqXSwgYXJyYXlbaV1dOyAvLyBTd2FwIGVsZW1lbnRzCiAgfQp9CgpmdW5jdGlvbiBtZXJnZShhcnIxLCBhcnIyKSB7CiAgY29uc3QgbWVyZ2VkID0gW107CiAgbGV0IGkgPSAwOwogIGxldCBqID0gMDsKCiAgd2hpbGUgKGkgPCBhcnIxLmxlbmd0aCB8fCBqIDwgYXJyMi5sZW5ndGgpIHsKICAgIGlmIChNYXRoLnJhbmRvbSgpIDwgMC41ICYmIGkgPCBhcnIxLmxlbmd0aCkgewogICAgICBtZXJnZWQucHVzaChhcnIxW2ldKTsKICAgICAgaSsrOwogICAgfSBlbHNlIGlmIChqIDwgYXJyMi5sZW5ndGgpIHsKICAgICAgbWVyZ2VkLnB1c2goYXJyMltqXSk7CiAgICAgIGorKzsKICAgIH0KICB9CgogIHJldHVybiBtZXJnZWQ7Cn0KCmZ1bmN0aW9uIGYobikgewogIGNvbnN0IHpvb3MgPSBbMCwgMSwgMTBdOwogIGNvbnN0IHpvbyA9IFtdOwogIGNvbnN0IHJlc3VsdCA9IFtdOwogIGZvciAobGV0IGkgPSAwOyBpIDwgMTI7IGkrKykgewogICAgaWYgKCgxIDw8IGkpICYgbikgewogICAgICBpZiAoem9vcy5pbmNsdWRlcyhpKSkgewogICAgICAgIHpvby5wdXNoKGkpOwogICAgICB9IGVsc2UgewogICAgICAgIHJlc3VsdC5wdXNoKGkpOwogICAgICB9CiAgICB9CiAgfQogIHNodWZmbGVBcnJheShyZXN1bHQpOwogIHJldHVybihtZXJnZShyZXN1bHQsIHpvbykuam9pbignJykpOwp9CgpmdW5jdGlvbiBnKHMpIHsKICBsZXQgciA9IDA7CiAgbGV0IGkgPSAwOwogIHdoaWxlIChpIDwgcy5sZW5ndGgpIHsKICAgIGlmIChpIDwgcy5sZW5ndGggLSAxCiAgICAgICYmIFsnMTAnLCAnMTEnXS5pbmNsdWRlcyhzW2ldICsgc1tpKzFdKSkgewogICAgICByICs9IDEgPDwgTnVtYmVyKHNbaV0gKyBzW2krMV0pOwogICAgICBpICs9IDE7CiAgICB9IGVsc2UgewogICAgICByICs9IDEgPDwgTnVtYmVyKHNbaV0pOwogICAgfQogICAgaSArPSAxOwogIH0KICByZXR1cm4gcjsKfQoKY29uc3QgbiA9IDEzNTUKcHJpbnQoZihuKSk7CnByaW50KGcoZihuKSkpOw==