QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100

#6247. Parenthesis Happy

统计

A student has found a string of parentheses. They know that a correct parenthesis sequence is defined as follows:

  • () is a correct parenthesis sequence.
  • If $S$ is a correct parenthesis sequence, then $(S)$ is also a correct parenthesis sequence.
  • If $S$ and $T$ are correct parenthesis sequences, then $TS$, which is obtained by concatenating the two strings, is also a correct parenthesis sequence.

Furthermore, a cyclic shift of size $k$ on a string $S$ results in a string $T$ such that: $\forall 0 \le i < |S|, T[i] = S[(i + k) \pmod{|S|}]$

The student's happiness is equal to the number of $k$ values smaller than the length of the input string such that the cyclic shift of the string by size $k$ is a correct parenthesis sequence. Find this number and report it to the student so they become happy.

Input

The first line of the input contains the integer $n$, which is the length of the string. The second line of the input contains the string $S$ consisting of the characters '(' and ')'.

Output

In the only line of output, print the student's happiness, which is equivalent to the number of cyclic shifts of the string that are correct parenthesis sequences.

Constraints

  • $1 \le n \le 10^5$

Examples

Input 1

6
))()((

Output 1

2

Input 2

6
())(((

Output 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.