跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2560. Regular Bracket Sequence

  • ID: 2566
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:基础
  • 上传者:
  • 贪心
  • 算法思想
  • 基础
  • 难度
  • 共享题库
  • Codeforces
  • 英文题面
  • 题目来源
  • 题面语言

Regular Bracket Sequence

题目描述

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

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2207 题。保留原作者与原赛事署名。