Bracket Sequences


Problem Statement

Give a string ss of length nn consisting of only characters ( and ). Output the number of sub-sequences of ss which are equal to ().

This problem can be solved without divide and conquer, but for the purpose of this exercise, please use divide and conquer.

NOTE: A subsequence of ss is formed by deleting some characters from ss.

Input Format

Your first line will contain a single integer nn. Your next line will contain ss.

Output Format

Output the number of bracket sequences equal to () in ss.

Constraints

  • 1n1051 \leq n \leq 10^5

Sample Cases

Input 1
5
((())
Output 1
6
Input 2
10
)()()(()()
Output 2
12

Template

Code 1
n = int(input())
s = input()

# print your output

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.