合法括号序列AI (CI翻译)
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
如果可以在括号序列中插入字符 «+» 和 «1»,使其成为正确的算术表达式,那么这个括号序列就是合法的。例如,«(())()»、«()» 和 «(()(()))» 是合法的,而 «)(»、«(()» 和 «(()))(» 不是。AI (CI翻译)
One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
一天,约翰尼得到了一串括号。他决定从中删除一些括号,以得到一个合法的括号序列。能够得到的合法括号序列的最大长度是多少?AI (CI翻译)
Input
输入
AI (CI翻译)Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed $10^{6}$.
输入由一行组成,包含一个非空字符串,仅由 «(» 和 «)» 组成。字符串长度不超过 $10^{6}$。AI (CI翻译)
Output
输出
AI (CI翻译)Output the maximum possible length of a regular bracket sequence.
输出能够得到的合法括号序列的最大长度。AI (CI翻译)
样例
(()))(
4
((()())
6
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。