6227: [洛谷 202406GESP 模拟 二级] 小洛的田字矩阵

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

B. Regular Bracket Sequence
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output
Output the maximum possible length of a regular bracket sequence.
Examples
Input
(()))(
Output
4
Input
((()())
Output
6

输入样例 复制


输出样例 复制