process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
const inputArray = chunk.split(""); //? ['(', '(', ')', ')']
const values = [];
const CHARACTERS = {
"(": () => values.push("("),
")": () => {
if (values.length > 0 && values[values.length - 1] === "(") values.pop();
else values.push(")");
},
"?": () => {
if (values.length > 0 && values[values.length - 1] === "(") values.pop();
else values.push("(");
},
};
inputArray.forEach((char) => {
CHARACTERS[char]();
});
process.stdout.write(values.length.toString());
});
// Complejidad: O(n)
cHJvY2Vzcy5zdGRpbi5yZXN1bWUoKTsKcHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZygndXRmOCcpOwoKcHJvY2Vzcy5zdGRpbi5vbignZGF0YScsIGZ1bmN0aW9uIChjaHVuaykgewoJY29uc3QgaW5wdXRBcnJheSA9IGNodW5rLnNwbGl0KCIiKTsgLy8/IFsnKCcsICcoJywgJyknLCAnKSddCgkKCWNvbnN0IHZhbHVlcyA9IFtdOwoJCgljb25zdCBDSEFSQUNURVJTID0gewoJICAiKCI6ICgpID0+IHZhbHVlcy5wdXNoKCIoIiksCgkgICIpIjogKCkgPT4gewoJICAgIGlmICh2YWx1ZXMubGVuZ3RoID4gMCAmJiB2YWx1ZXNbdmFsdWVzLmxlbmd0aCAtIDFdID09PSAiKCIpIHZhbHVlcy5wb3AoKTsKCSAgICBlbHNlIHZhbHVlcy5wdXNoKCIpIik7CgkgIH0sCgkgICI/IjogKCkgPT4gewoJICAgIGlmICh2YWx1ZXMubGVuZ3RoID4gMCAmJiB2YWx1ZXNbdmFsdWVzLmxlbmd0aCAtIDFdID09PSAiKCIpIHZhbHVlcy5wb3AoKTsKCSAgICBlbHNlIHZhbHVlcy5wdXNoKCIoIik7CgkgIH0sCgl9OwoJCglpbnB1dEFycmF5LmZvckVhY2goKGNoYXIpID0+IHsKCSAgQ0hBUkFDVEVSU1tjaGFyXSgpOwoJfSk7CgkKCXByb2Nlc3Muc3Rkb3V0LndyaXRlKHZhbHVlcy5sZW5ndGgudG9TdHJpbmcoKSk7Cn0pOwoKLy8gQ29tcGxlamlkYWQ6IE8obik=