C. João Pessoa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Teams from UNICAMP at the beach of João Pessoa, in the Brazilian final of 2024

João Pessoa, the capital of Paraíba, is known for being the first city in Brazil to see the sun rise. On a special morning at Jacaré Beach, the locals were preparing for the famous sunrise spectacle accompanied by Ravel's Bolero. But there was a curious problem...

A local artist was preparing a decorative banner made only with parentheses '(' and ')', representing the movement of the sun on the horizon. The banner needed to be visually harmonious, meaning the sequence of parentheses had to be balanced. Formally, at every position in the banner, the number of opening parentheses up to that point must never be less than the number of closing parentheses. Some examples are "()", "(())()", or "()()(()()())".

However, when it came time to place the parentheses on the banner, he realized he had glued them in the wrong order! Since the total number of '(' and ')' is still correct and equal, the artist decided to cut the banner, removing some parentheses from the beginning and then sewing them to the end, without changing the order or direction. More formally, he performs a cyclic rotation — that is, moving some characters from the beginning of the banner to the end.

Your task is to help the artist figure out how many characters from the beginning need to be moved to the end for the sequence to become valid. It can be proven that under these conditions, there is always a valid rotation. If there is more than one way to do this, you may choose any of them.

Input

The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 5 \cdot 10^5$$$), representing the length of the banner.

The second line contains a string $$$S$$$ of length $$$N$$$, composed only of the characters '(' and ')'. It is guaranteed that the number of '(' will be equal to the number of ')'.

Output

Print a single integer $$$0 \leq r \lt N$$$, indicating that by moving the first $$$r$$$ characters to the end, we will have a valid banner. That is, $$$S_{r+1}, S_{r+2}... S_{N}, S_1, S_2... S_{r}$$$ is a valid banner. If there is more than one answer, print any of them.

Examples
Input
6
))((()
Output
2
Input
2
()
Output
0
Input
4
))((
Output
2