题库练习 Regular Bracket Sequence
← 上一题 下一题 →

A7822 | Regular Bracket Sequence

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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.

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?

输入格式

Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed $10^{6}$ .

输出格式

Output the maximum possible length of a regular bracket sequence.

输入输出样例

输入 #1
(()))(
输出 #1
4
输入 #2
((()())
输出 #2
6
C++ 编辑器
输入
输出