process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
const input = chunk.trim();
if (Math.abs(input.length) <= 5000) {
const stack = [];
for (const char of input) {
if (char === '(') stack.push(char);
else if (char === ')') {
if (stack.length > 0 && stack[stack.length - 1] === '(') stack.pop();
else stack.push(char);
}
else if (char === '?') {
if (stack.length > 0 && stack[stack.length - 1] === '(') stack.pop();
else stack.push(char);
}
}
console.log(stack.length);
}
else console.log("La cadena supera el límite de longitud permitido.");
});
cHJvY2Vzcy5zdGRpbi5yZXN1bWUoKTsKcHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZygndXRmOCcpOwoKcHJvY2Vzcy5zdGRpbi5vbignZGF0YScsIGZ1bmN0aW9uIChjaHVuaykgewogICAgY29uc3QgaW5wdXQgPSBjaHVuay50cmltKCk7CiAgICBpZiAoTWF0aC5hYnMoaW5wdXQubGVuZ3RoKSA8PSA1MDAwKSB7CiAgICAJY29uc3Qgc3RhY2sgPSBbXTsKCSAgICBmb3IgKGNvbnN0IGNoYXIgb2YgaW5wdXQpIHsKCSAgICAgICAgaWYgKGNoYXIgPT09ICcoJykgc3RhY2sucHVzaChjaGFyKTsKCSAgICAgICAgZWxzZSBpZiAoY2hhciA9PT0gJyknKSB7CgkgICAgICAgICAgICBpZiAoc3RhY2subGVuZ3RoID4gMCAmJiBzdGFja1tzdGFjay5sZW5ndGggLSAxXSA9PT0gJygnKSBzdGFjay5wb3AoKTsKCSAgICAgICAgICAgIGVsc2Ugc3RhY2sucHVzaChjaGFyKTsKCSAgICAgICAgfQoJICAgICAgICBlbHNlIGlmIChjaGFyID09PSAnPycpIHsKCSAgICAgICAgICAgIGlmIChzdGFjay5sZW5ndGggPiAwICYmIHN0YWNrW3N0YWNrLmxlbmd0aCAtIDFdID09PSAnKCcpIHN0YWNrLnBvcCgpOwoJICAgICAgICAgICAgZWxzZSBzdGFjay5wdXNoKGNoYXIpOwoJICAgICAgICB9CgkgICAgfQoJICAgIGNvbnNvbGUubG9nKHN0YWNrLmxlbmd0aCk7CiAgICB9CiAgICBlbHNlIGNvbnNvbGUubG9nKCJMYSBjYWRlbmEgc3VwZXJhIGVsIGzDrW1pdGUgZGUgbG9uZ2l0dWQgcGVybWl0aWRvLiIpOwp9KTsK