Codeforces Round 583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
C
Bad Sequence
Codeforces
1200
原题
← BD →
翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

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.

翻译中…

样例

Input #1
2
)(
Output #1
Yes
InputCopy OutputCopy
Input #2
3
(()
Output #2
No
InputCopy OutputCopy
Input #3
2
()
Output #3
Yes
InputCopy OutputCopy
Input #4
10
)))))(((((
Output #4
No
InputCopy OutputCopy
题目信息
题号
1214C
时间限制
1 s
内存限制
512 MB
标签
数据结构
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。