Topic 2: Carp flag at the resort (Hihocoder Challenge 20)

Source: Internet
Author: User

Topic 2: The time limit of Carp flag in the exhibition resort:10000msSingle Point time limit:1000msMemory Limit:256MB
Describe

Yanshou County North listed "North City Park Exhibition Resort", is one of the three major cherry blossom Mutsu. Every year from mid-April to early May, there will be a grand memorial ceremony. In addition to the cherry blossom trails, you can take the sightseeing wagon Xu Xing, and the CARP flag across the North River, along with the local special borrowing strategy to worship the ancestors and the North Ghost Sword Dance.

Let's say we use a parenthesis string containing ' (', ') ' to distinguish the direction of each side of the CARP flag. A sequence of parentheses is called legal when and only if two conditions are met: first, for the entire sequence, the number of opening brackets equals the closing parenthesis; for any prefix, the number of opening brackets is not less than the number of closing parentheses. Island Niang want to know, for a string of parentheses, how many substrings are legal, you can help her.

Input

The input data is only one row, containing a length of n (1?≤? n ?? ≤?106) of the parentheses string.

Output

Outputs a row that represents the number of valid parentheses substrings.

Sample input
(()())
Sample output
4

Understand test instructions understand for half a day.

For any prefix, the number of opening brackets is not less than the number of closing brackets.

The meaning of this sentence is that the current string as the prefix of the other strings must satisfy the number of opening parentheses not less than the number of closing parentheses NND: Do I have a bad language? I've been reading it.



Title 2: Carp flag at the resort (Hihocoder Challenge)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.