Preparando MOJI

Regular Bracket Sequence

5000ms 262144K

Description:

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.

Sample Input:

(()))(

Sample Output:

4

Sample Input:

((()())

Sample Output:

6

Informação

Codeforces

Provedor Codeforces

Código CF26B

Tags

greedy

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 08:27:24

Relacionados

Nada ainda