CF1095E.Almost Regular Bracket Sequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a bracket sequence ss consisting of nn opening '(' and closing ')' brackets.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

You can change the type of some bracket sis_i . It means that if $s_i = $ ')' then you can change it to '(' and vice versa.

Your task is to calculate the number of positions ii such that if you change the type of the ii -th bracket, then the resulting bracket sequence becomes regular.

输入格式

The first line of the input contains one integer nn ( 1n1061 \le n \le 10^6 ) — the length of the bracket sequence.

The second line of the input contains the string ss consisting of nn opening '(' and closing ')' brackets.

输出格式

Print one integer — the number of positions ii such that if you change the type of the ii -th bracket, then the resulting bracket sequence becomes regular.

输入输出样例

  • 输入#1

    6
    (((())
    

    输出#1

    3
    
  • 输入#2

    6
    ()()()
    

    输出#2

    0
    
  • 输入#3

    1
    )
    

    输出#3

    0
    
  • 输入#4

    8
    )))(((((
    

    输出#4

    0
    
首页