Bad Sequence
Contest: Codeforces Round 583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
Difficulty rating: 1200
Tags: data structures, greedy

Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself.

To make everything right, Petya is going to move at most one bracket from its original place in the sequence to any other position. Reversing the bracket (e.g. turning "(" into ")" or vice versa) isn't allowed.

We remind that bracket sequence $$$s$$$ is called correct if:

- $$$s$$$ is empty;
- $$$s$$$ is equal to "($$$t$$$)", where $$$t$$$ is correct bracket sequence;
- $$$s$$$ is equal to $$$t_1 t_2$$$, i.e. concatenation of $$$t_1$$$ and $$$t_2$$$, where $$$t_1$$$ and $$$t_2$$$ are correct bracket sequences.

For example, "(()())", "()" are correct, while ")(" and "())" are not. Help Petya to fix his birthday present and understand whether he can move one bracket so that the sequence becomes correct.

Input format:
First of line of input contains a single number $$$n$$$ ($$$1 \leq n \leq 200\,000$$$) — length of the sequence which Petya received for his birthday.

Second line of the input contains bracket sequence of length $$$n$$$, containing symbols "(" and ")".

Output format:
Print "Yes" if Petya can make his sequence correct moving at most one bracket. Otherwise print "No".

Constraints:
Time limit: 1.0 s
Memory limit: 512.0 MB

Note:
In the first example, Petya can move first bracket to the end, thus turning the sequence into "()", which is correct bracket sequence.

In the second example, there is no way to move at most one bracket so that the sequence becomes correct.

In the third example, the sequence is already correct and there's no need to move brackets.

Example input:
2
)(

Example output:
Yes

Example input:
3
(()

Example output:
No

Editorial:
Let's call a balance of bracket sequence a number of opening brackets minus the number of closing brackets. Correct bracket sequence is such a sequence that balance of any of its prefixes is at least $$$0$$$ and the balance of the entire sequence is equal to $$$0$$$.
To solve the problem let's consider the shortest prefix with balance equal to $$$-1$$$. In this prefix last symbol is obviously equal to ")", so let's move this closing bracket to the end of the sequence. If the sequence is correct now, then the answer is "Yes", otherwise it is "No", because it means that in original sequence there exists some longer prefix with balance equal to $$$-2$$$. Let's show why we can't move some bracket so that the sequence becomes correct.
Consider the shortest prefix with balance equal to $$$-2$$$. If we move some opening bracket to the beginning of the sequence, balance of considered prefix becomes $$$-1$$$ and the sequence is not correct yet. Moving opening bracket from considered prefix to the beginning doesn't change anything. Even more, if we move the closing bracket from the end of the considered prefix to the end of the sequence, it still doesn't become correct, because balance of the prefix is $$$-1$$$.
This results in a following solution: if balance of all prefixes is not less than $$$-1$$$, answer is "Yes", otherwise it's "No".