function decompressedLen2(input) {
const weights = new Array(input.length).fill(1);
let [len, i] = [0, 0];
while (i < input.length) {
if (input[i] === "(") {
const markerEnd = input.indexOf(")", i);
const [n, r] = input
.substring(i + 1, markerEnd)
.split("x")
.map(Number);
for (let j = 0; j < n; j++) {
weights[j + markerEnd + 1] *= r;
}
i = markerEnd + 1;
} else {
len += weights[i];
i++;
}
}
return len;
}