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".


-----Examples-----
Input
2
)(

Output
Yes

Input
3
(()

Output
No

Input
2
()

Output
Yes

Input
10
)))))(((((

Output
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.

Difficulty: EASY
Tags: Data structures

Greedy algorithms
Skill types: Data structures

Greedy algorithms

Starter code:

Solutions:
import sys
import bisect
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
st = ri()
summ = 0
ans = 0
tot = 0
for i in range(n):
	if st[i] == '(':
		summ += 1
		tot += 1
	else:
		summ -= 1
		tot -= 1
	if summ < 0:
		ans += 1
		summ = 0
if tot != 0:
	No()
elif ans > 1:
	No()
else:
	Yes()


def read():
	n = int(input())
	s = input()
	return (n, s)

def solve(n, s):
	st = [s[0]]
	for i in range(1, n):
		if s[i] == '(':
			st.append(s[i])
		elif len(st) == 0:
			st.append(s[i])
		elif st[-1] == '(':
			st.pop()
		else:
			st.append(s[i])
	if len(st) == 0:
		return True
	elif len(st) == 2:
		return st[0] != st[1]
result = solve(*read())
print('Yes' if result else 'No')


n = int(input())
s = input()
if n & 1:
	print('NO')
	exit(0)
(wrong, extra) = (0, 0)
(st, en) = (0, 0)
for (ind, i) in enumerate(s):
	if i == '(':
		st += 1
	else:
		en += 1
	if en > st + 1:
		print('NO')
		exit(0)
if en == st:
	print('YES')
else:
	print('NO')


input()
s = input()
e = 0
ok = True
for v in s:
	if v == '(':
		e += 1
	elif v == ')':
		e -= 1
	if e < -1:
		ok = False
print('Yes' if ok and e == 0 else 'No')


b = int(input())
st = input()
ans = 0
fl = 0
for c in st:
	if len(st) % 2 == 1:
		fl = 1
		print('No')
		break
	if c == '(':
		ans += 1
	if c == ')':
		ans -= 1
	if ans == -2:
		fl = 1
		print('No')
		break
if fl == 0 and ans == 0:
	print('Yes')
elif fl == 0 and ans != 0:
	print('No')


n = int(input())
s = input()
depth = 0
ig = False
for i in range(n):
	if not ig and s[i] == ')':
		ig = True
		continue
	if s[i] == '(':
		depth += 1
	else:
		depth -= 1
	if depth < 0:
		print('No')
		return
if ig:
	depth -= 1
if depth:
	print('No')
else:
	print('Yes')


n = int(input())
string = input().strip()
if string.count('(') != string.count(')'):
	print('No')
else:
	(lcount, rcount) = (0, 0)
	flag = 1
	for i in string:
		if i == '(':
			lcount += 1
		if i == ')':
			rcount += 1
		if rcount - lcount > 1:
			flag = 0
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


from sys import stdin

def sin():
	return stdin.readline()
n = int(sin())
s = sin()
if n % 2 != 0:
	print('No')
else:
	t = 1
	for i in s:
		if i == ')':
			t -= 1
		elif i == '(':
			t += 1
		if t < 0:
			break
	if t == 0 or t == 1:
		print('Yes')
	else:
		print('No')


n = int(input())
l = input()
a = []
if l.count('(') == l.count(')'):
	for i in l:
		if i == '(':
			a.append(i)
		elif i == ')':
			if not a:
				continue
			else:
				a.pop()
	if len(a) == 1 or len(a) == 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
s = input()
bal = 0
worst = 0
for i in s:
	if i == '(':
		bal += 1
	else:
		bal -= 1
	worst = min(bal, worst)
if bal != 0:
	print('NO')
else:
	print('YES' if worst >= -1 else 'NO')


n = int(input())
s = input()
c = 0
m = 0
for i in s:
	if i == '(':
		c += 1
	else:
		c -= 1
	m = min(m, c)
if m >= -1 and c == 0:
	print('YES')
else:
	print('NO')


d = int(input())
f = input()
count = 0
count1 = 0
count3 = 0
count4 = 0
for i in range(d):
	if f[i] == ')':
		count3 += 1
		count -= 1
		if count < -1:
			count1 += 1
	else:
		count4 += 1
		count += 1
if count1 > 0:
	print('No')
elif count3 == count4:
	print('Yes')
else:
	print('No')


dlug = int(input())
(i_otw, i_zam) = (0, 0)
for x in input():
	if x == '(':
		i_otw += 1
	else:
		i_zam += 1
	if i_zam > i_otw + 1:
		print('No')
		break
else:
	if i_zam > i_otw or i_otw > i_zam:
		print('No')
	else:
		print('Yes')


n = int(input())
s = input()
c = k = 0
if n % 2 == 0:
	for i in range(n):
		if s[i] == '(':
			c += 1
		else:
			c -= 1
		if c <= -2:
			k = 1
			break
else:
	k = 1
if k == 1 or abs(c) > 1:
	print('No')
else:
	print('Yes')


n = int(input())
s = input()
c = 0
if n % 2:
	print('No')
	exit()
for b in s:
	if b == '(':
		c += 1
	else:
		c -= 1
if c == 0:
	op = 0
	cl = 0
	d = 0
	for b in s[::-1]:
		if b == '(':
			op += 1
		else:
			cl += 1
		if op - cl > 1:
			d = 1
			break
	if d:
		print('No')
	else:
		print('Yes')
else:
	print('No')


n = int(input())
bra = input()
count = 0
for i in bra:
	if i == '(':
		count += 1
	elif i == ')':
		count -= 1
	if count < -1:
		break
if count < -1 or n % 2 != 0 or count > 0:
	print('No')
else:
	print('Yes')


input = __import__('sys').stdin.readline
from collections import deque
N = int(input())
s = input().rstrip()
if not s:
	print('Yes')
	exit()
stack = deque()
L = 0
R = 0
stack.append(s[0])
for i in range(N):
	if i == '(':
		L += 1
	else:
		R += 1
c_same = False
if L == R:
	c_same = True
for i in range(1, N):
	if stack:
		top = stack[-1]
		if top == '(' and s[i] == ')':
			stack.pop()
		else:
			stack.append(s[i])
	else:
		stack.append(s[i])
if not stack:
	print('Yes')
elif len(stack) == 2 and stack[0] != stack[1]:
	print('Yes')
else:
	print('No')


def check(s, n):
	balance = [None] * n
	balance[0] = 1 if s[0] == '(' else -1
	for i in range(1, n):
		if s[i] == '(':
			balance[i] = balance[i - 1] + 1
		else:
			balance[i] = balance[i - 1] + -1
	for i in range(n):
		if balance[i] < -1:
			return 'No'
	if balance[-1] == 0:
		return 'Yes'
	else:
		return 'No'
n = int(input())
s = input().rstrip().lstrip()
print(check(s, n))


n = int(input())
word = input()
if n & 1 or word.count('(') != n // 2:
	print('No')
	exit(0)
ind = word.rfind('(')
word = '(' + word[:ind] + word[ind + 1:]
op = 0
for p in word:
	if p == '(':
		op += 1
	else:
		op -= 1
	if op < 0:
		print('No')
		exit()
print('Yes')


def main():
	n = int(input())
	s = input()
	tab = []
	inc = 0
	if s.count('(') != s.count(')'):
		print('No')
		return
	for x in range(n):
		if s[x] == ')':
			inc -= 1
		else:
			inc += 1
		tab.append(inc)
	if min(tab) >= -1:
		print('Yes')
	else:
		print('No')
main()


n = int(input())
a = list(input())
flag = 0
count = 0
for i in range(n):
	if a[i] == '(':
		count += 1
	else:
		count -= 1
	if count == -1:
		if i == n - 1:
			flag += 1
		elif a[i + 1] == ')':
			print('No')
			exit(0)
		else:
			count = 0
			flag += 1
co = 0
for i in range(n):
	if a[i] == '(':
		co += 1
	else:
		co -= 1
if flag <= 1 and co == 0:
	print('Yes')
else:
	print('No')


import math
n = int(input())
string = str(input())
(left, right) = (0, 0)
for i in range(n):
	if string[i] == ')':
		right += 1
	else:
		left += 1
if math.fabs(right - left) != 0:
	print('No')
	exit(0)
del right, left
digit = 0
for i in range(n):
	if string[i] == '(':
		digit += 1
	else:
		digit -= 1
	if digit < -1:
		print('No')
		exit(0)
print('Yes')


n = int(input())
a = input()
s = []
for i in a:
	if s and i == ')':
		if s[-1] == '(':
			s.pop(-1)
		else:
			s.append(')')
	else:
		s.append(i)
if len(s) == 0:
	print('Yes')
elif len(s) != 2:
	print('No')
elif s == [')', '(']:
	print('Yes')
else:
	print('No')


n = int(input())
s = list(input())
if n % 2 != 0:
	print('NO')
	exit()
a = []
k = []
for i in range(n):
	if s[i] == '(':
		a.append(s[i])
	elif len(a) == 0:
		k.append(s[i])
	else:
		a.pop()
if len(a) == 0 and len(k) == 0:
	print('YES')
	exit()
if len(a) == 1 and len(k) == 1:
	print('YES')
	exit()
else:
	print('NO')


def main():
	n = input()
	s = input()
	left = 0
	right = 0
	for i in s:
		if i == ')':
			left += 1
		else:
			right += 1
		if left - right > 1:
			print('NO')
			return
	if left == right:
		print('YES')
	else:
		print('NO')
	return
main()


def bad_sequence(n, s):
	if n % 2 == 1:
		return 'NO'
	(left_bracket, right_bracket) = (0, 0)
	for elem in s:
		if elem == '(':
			left_bracket += 1
		elif left_bracket > 0:
			left_bracket -= 1
		elif right_bracket < 1:
			right_bracket += 1
		else:
			return 'NO'
	left_bracket -= right_bracket
	if left_bracket == 0:
		return 'YES'
	return 'NO'
m = int(input())
t = input()
print(bad_sequence(m, t))


n = int(input())
s = input()
if n % 2 == 1:
	print('NO')
	exit()
ot = 0
zac = 0
for i in s:
	if i == '(':
		ot += 1
	else:
		zac += 1
	if zac > ot + 1:
		print('NO')
		exit()
if ot == zac:
	print('YES')
else:
	print('NO')


import sys, math
n = int(input())
s = input()
c = 0
ans = 'Yes'
if n % 2 != 0:
	ans = 'No'
else:
	for i in range(n):
		if s[i] == ')':
			c -= 1
		else:
			c += 1
		if c < -1:
			ans = 'No'
if c != 0:
	ans = 'No'
print(ans)


n = int(input())
s = list(input())
if n % 2 == 1:
	print('No')
	exit()
s = [0 if x == '(' else 1 for x in s]
if sum(s) != n // 2:
	print('No')
	exit()
count = 0
for i in range(n):
	if s[i] == 0:
		count += 1
	else:
		count -= 1
	if count <= -2:
		print('No')
		exit()
print('Yes')


n = int(input())
s = input()
t = []
for i in s:
	if i == '(':
		t.append(i)
	elif len(t) and t[-1] == '(':
		del t[-1]
print('Yes' if s.count('(') == s.count(')') and len(t) <= 1 else 'No')


n = int(input())
p = 0
a = list(map(lambda x: 1 if x == '(' else -1, input()))
if n % 2 or a.count(-1) != a.count(1):
	exit(print('NO'))
else:
	for i in a:
		p += i
		if p < -1:
			exit(print('NO'))
print('YES')


import sys
Lines = []
for Line in sys.stdin:
	Lines.append(Line.rstrip('\n'))
n = int(Lines[0])
del Lines[0]
t = Lines[0]
stack = []
stack2 = []
nb_ouv = t.count('(')
if nb_ouv != n - nb_ouv:
	print('No')
	exit(0)
for p in t:
	if p == '(':
		stack += ['(']
	elif p == ')':
		if len(stack) != 0:
			stack.pop(0)
		else:
			stack2 += [')']
if len(stack) < 2 and len(stack2) < 2:
	print('Yes')
else:
	print('No')


n = int(input())
s = list(input())
stack = []
for (i, num) in enumerate(s):
	if len(stack) == 0:
		stack.append(num)
	elif stack[-1] == '(' and num == ')':
		stack.pop()
	else:
		stack.append(num)
if len(stack) == 2 and stack[0] != stack[1] or len(stack) == 0:
	print('Yes')
else:
	print('No')


n = int(input())
(kappa, nmb) = (0, 0)
bras = input()
for i in range(n):
	if bras[i] == '(':
		kappa += 1
	else:
		kappa -= 1
	nmb = min(nmb, kappa)
print('YES') if nmb >= -1 and kappa == 0 else print('NO')


n = int(input())
s = input()
s = list(s)
l = 0
r = 0
p = 0
k = []
for i in s:
	if i == '(':
		l += 1
		k.append(i)
	else:
		r += 1
		if len(k) > 0:
			k.pop()
			p += 1
if l == r and (l - 1 == p or l == p):
	print('Yes')
else:
	print('No')


input()
s = m = 0
for c in input():
	s += (1, -1)[c > '(']
	m = min(m, s)
print('YNeos'[s != 0 or -1 > m::2])


n = int(input())
s = input().strip()
op = s.count('(')
cl = s.count(')')
if op != cl:
	print('No')
else:
	ops = 0
	cls = 0
	mistakes = 0
	for i in range(n):
		if s[i] == '(':
			ops += 1
		elif s[i] == ')':
			if ops > 0:
				ops -= 1
			else:
				cls += 1
				mistakes += 1
	if ops != 0:
		mistakes += ops
	if mistakes == 2 or mistakes == 0:
		print('Yes')
	else:
		print('No')


import sys
input()
c = input()
if not '(' in c:
	print('No')
	return
last = c.rfind('(')
corr = '(' + c[:last] + c[last + 1:]
sums = 0
for br in corr:
	if br == '(':
		sums += 1
	else:
		sums -= 1
	if sums < 0:
		print('No')
		return
print('Yes' if sums == 0 else 'No')


n = int(input())
A = []
s = input()
if n % 2 == 1:
	print('NO')
else:
	for i in range(n):
		if A != [] and A[-1] + s[i] == '()':
			A.pop(-1)
		else:
			A.append(s[i])
	k = len(A)
	if k == 2:
		s1 = A[0] + A[1]
		if s1 == ')(':
			print('YES')
		else:
			print('NO')
	elif k == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
n = int(input())
S = input().strip()
NOW = 0
SC = []
for s in S:
	if s == '(':
		NOW += 1
	else:
		NOW -= 1
	SC.append(NOW)
if SC[-1] == 0 and min(SC) >= -1:
	print('Yes')
else:
	print('No')


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def unique(sequence):
	seen = set()
	return [x for x in sequence if not (x in seen or seen.add(x))]
n = int(I1())
s = I1().strip()
c = 0
for x in s:
	if x == '(':
		c += 1
	else:
		c -= 1
	if c < -1:
		print('No')
		exit()
if c == 0:
	print('Yes')
else:
	print('No')


n = int(input())
b = str(input())
stack = ['' for i in range(n)]
top = 0
for i in range(n):
	if len(stack) == 0:
		stack[top] = b[i]
		continue
	if b[i] == '(':
		stack[top] = b[i]
		top += 1
	elif b[i] == ')':
		if stack[top - 1] == '(':
			top -= 1
		else:
			stack[top] = ')'
			top += 1
if top == 0 or (top == 2 and stack[0] == ')' and (stack[1] == '(')):
	print('Yes')
else:
	print('No')


n = int(input())
string = str(input())
balance = 0
cc = 0
for el in string:
	if el == '(':
		balance += 1
	else:
		balance -= 1
	cc = min(cc, balance)
if balance == 0 and cc >= -1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(input())
x = 0
flag = 0
for i in range(n):
	if a[i] == '(':
		x += 1
	elif x > -1:
		x -= 1
	else:
		flag = 1
		break
if flag == 1 or x != 0:
	print('No')
else:
	print('Yes')


(n, s) = (int(input()), input())
nums_o = s.count('(')
nums_c = s.count(')')
if n % 2 or nums_c != nums_o:
	print('No')
else:
	cnt = 0
	stack = []
	for c in s:
		if c == '(':
			stack.append(c)
		elif len(stack) != 0:
			stack.pop()
		else:
			cnt += 1
			if cnt == 2:
				print('No')
				break
	else:
		print('Yes')


num = int(input())
if num % 2 == 1:
	print('No')
	exit()
bracket = list(input())
st = bracket[0]
stack = []
one = 0
two = 0
for (i, a) in enumerate(bracket):
	if a == '(':
		one += 1
		stack.append([a, i])
	else:
		two += 1
		if stack:
			check = stack.pop()
			bracket[i] = '_'
			bracket[check[1]] = '_'
if one != two:
	print('No')
	exit()
s = ''
i = 0
while i < len(bracket):
	if bracket[i] != '_':
		s += bracket[i]
	i += 1
if len(s) <= 2:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
c = 0
for i in s:
	if i == '(':
		c += 1
	else:
		c -= 1
		if c < -1:
			print('NO')
			exit(0)
print('YES' if c == 0 else 'NO')


n = int(input())
str = input()
bal = 0
for i in range(n):
	bal += 1
	if str[i] == ')':
		bal -= 2
	if bal < -1:
		print('No')
		break
else:
	print('Yes' if bal == 0 else 'No')


n = int(input())
inp = input()
arr = []
m = 0
if n % 2 != 0:
	print('No')
else:
	for i in inp:
		if i == '(':
			arr.append('(')
		elif i == ')':
			if arr:
				arr.pop()
			else:
				m += 1
	if m == 1 and len(arr) == 1 or (m == 0 and len(arr) == 0):
		print('Yes')
	else:
		print('No')


n = int(input())
m = input()
bracketlist = []
for j in m:
	bracketlist.append(j)
ls = []
for j in bracketlist:
	if j == '(':
		ls.append(1)
	else:
		ls.append(-1)
balancelist = []
for j in bracketlist:
	balancelist.append(0)
if bracketlist[0] == '(':
	balancelist[0] = 1
else:
	balancelist[0] = -1
for j in range(1, len(bracketlist)):
	balancelist[j] = balancelist[j - 1] + ls[j]
stop = False
if balancelist[-1] != 0:
	print('NO')
	stop = True
if stop == False:
	for j in balancelist:
		if j <= -2:
			stop = True
			print('NO')
			break
if stop == False:
	print('YES')


n = int(input())
s = input()
if 2 * s.count('(') != n:
	print('No')
	exit(0)
b = 0
f = False
(kz, kkz) = (0, 0)
for i in range(n):
	if s[i] == '(':
		b += 1
	else:
		b -= 1
	if b == -1 and (not f):
		b = 0
		f = True
	if f:
		if b == 0:
			kz = i
		elif b > 0:
			kkz = i
		else:
			print('No')
			exit(0)
if kkz > kz or not f:
	print('Yes')
else:
	print('No')


n = int(input())
a = list(input())
c = 0
for i in a:
	if i == '(':
		c += 1
	else:
		c -= 1
	if c <= -2:
		break
if c <= -2 or c != 0:
	print('NO')
else:
	print('Yes')


import math
import sys
from collections import defaultdict
rt = lambda : map(int, input().split())
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))

def main():
	n = ri()
	s = input()
	(l, r) = (0, 0)
	pickedR = False
	ok = True
	for val in s:
		if val == '(':
			l += 1
		else:
			r += 1
		if r > l:
			if pickedR:
				ok = False
				break
			pickedR = True
			r -= 1
	if pickedR and r + 1 != l:
		ok = False
	if not pickedR and l != r:
		ok = False
	print('YES' if ok else 'NO')
main()


n = int(input())
s = input()
mnl = 0
cntl = 0
for i in range(n):
	if s[i] == '(':
		cntl += 1
	else:
		cntl -= 1
	mnl = min(cntl, mnl)
	if mnl <= -2:
		print('No')
		exit()
if cntl != 0:
	print('No')
else:
	print('Yes')


input()
s = input()
b = 0
min_b = 0
for i in range(len(s)):
	if s[i] == '(':
		b += 1
	else:
		b -= 1
	min_b = min(min_b, b)
if min_b >= -1 and b == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
open = 0
close = 0
for i in range(len(s)):
	if s[i] == '(':
		open += 1
	else:
		close += 1
if open != close:
	print('NO')
else:
	open = 0
	close = 0
	x = 0
	for i in range(len(s)):
		if s[i] == '(':
			open += 1
		else:
			close += 1
		if close > open:
			x += 1
			close = 0
			open = 0
	if x > 1:
		print('NO')
	else:
		print('YES')


n = int(input())
s = input()
stack = []
l = 0
r = 0
cnt = 0
for i in s:
	if i == '(':
		stack.append('(')
		l += 1
	else:
		if len(stack) > 0:
			stack.pop(-1)
		else:
			cnt += 1
		r += 1
if len(stack) == 0 and abs(l - r) == 0 or (abs(l - r) == 0 and l == 1):
	print('Yes')
elif len(stack) == 1 and cnt == 1:
	print('Yes')
else:
	print('No')


b = int(input())
g = input()
n = 0
m = 0
e = 0
for i in g:
	if i == '(':
		n += 1
	elif i == ')' and n == m:
		e += 1
	else:
		m += 1
if e <= 1 and n == m + e:
	print('Yes')
else:
	print('No')


n = int(input(''))
strr = input('')
cnt1 = 0
cnt2 = 0
for i in range(n):
	if strr[i] == '(':
		cnt1 += 1
	else:
		cnt2 += 1
if cnt1 != cnt2:
	print('No')
else:
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if strr[i] == '(':
			cnt1 += 1
		elif cnt1 > 0:
			cnt1 -= 1
	if cnt1 < 2:
		print('Yes')
	else:
		print('NO')


from collections import Counter
n = int(input())
bra = input()
d = Counter(bra)
ans = 0
if d['('] == d[')']:
	c = 0
	for i in bra:
		if i == '(':
			c += 1
		elif c == 0:
			ans += 1
		else:
			c -= 1
	if ans <= 1:
		print('Yes')
	else:
		print('No')
else:
	print('No')


n = int(input())
s = input()
cur = 0
chk = True
for i in range(n):
	if s[i] == ')':
		cur -= 1
	else:
		cur += 1
	if cur < -1:
		chk = False
print('Yes' if chk == True and cur == 0 else 'No')


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
else:
	balance = 0
	f = True
	for i in s:
		if i == ')':
			balance -= 1
		else:
			balance += 1
		if balance < -1:
			f = False
	if f and balance == 0:
		print('Yes')
	else:
		print('No')


input()
d = r = 0
for c in input():
	d += {'(': 1, ')': -1}[c]
	if d < -1:
		r = 1
print(('Yes', 'No')[r or d != 0])


n = int(input())
s = input()
sum = 0
for i in range(0, len(s)):
	if s[i] == '(':
		sum += 1
	if s[i] == ')':
		sum -= 1
	if sum < -1:
		print('No')
		exit(0)
if sum == 0:
	print('Yes')
else:
	print('No')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return list(map(int, input().split()))

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()

def addDictList(d, key, val):
	if key not in d:
		d[key] = []
	d[key].append(val)

def addDictInt(d, key, val):
	if key not in d:
		d[key] = 0
	d[key] = val

def addDictCount(d, key):
	if key not in d:
		d[key] = 0
	d[key] += 1

def addDictSum(d, key, val):
	if key not in d:
		d[key] = 0
	d[key] += val
n = getInt()
s = getStr()
if n % 2 == 1:
	r = 'No'
else:
	r = 'Yes'
	num = 0
	for i in range(n):
		if s[i] == '(':
			num += 1
		else:
			num -= 1
			if num < -1:
				r = 'No'
				break
	if num != 0:
		r = 'No'
print(r)


li = []
n = int(input())
s = input()
a = s.count('(')
b = s.count(')')
if a != b:
	flag = 'No'
else:
	for i in s:
		if i == '(':
			li.append(1)
		elif i == ')':
			if len(li) > 0 and li[-1] == 1:
				li.pop()
			elif len(li) == 0:
				li.append(2)
	if len(li) <= 2:
		flag = 'Yes'
	else:
		flag = 'No'
print(flag)


t = 1
for _ in range(t):
	n = int(input())
	a = input()
	stack = []
	(o, c) = (0, 0)
	flag = 0
	for i in a:
		if i == '(':
			stack.append(i)
			o += 1
		else:
			if stack:
				stack.pop()
			else:
				flag += 1
			c += 1
	if o != c:
		print('No')
	elif not stack:
		print('Yes')
	elif flag == 1:
		print('Yes')
	else:
		print('No')


def check(s):
	bal = 0
	for i in range(len(s)):
		if s[i] == '(':
			bal += 1
		elif s[i] == ')':
			bal -= 1
		if bal < 0:
			return False
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '(':
			bal += 1
		elif s[i] == ')':
			bal -= 1
		if bal > 0:
			return False
	if bal == 0:
		return True
	else:
		return False

def check2(s):
	bal = 0
	for i in range(len(s)):
		if s[i] == '(':
			bal += 1
		elif s[i] == ')':
			bal -= 1
		if bal < -1:
			return False
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '(':
			bal += 1
		elif s[i] == ')':
			bal -= 1
		if bal > 1:
			return False
	if bal == 0:
		return True
	else:
		return False

def func():
	n = int(input())
	s = input()
	if len(s) % 2 != 0:
		print('No')
		return
	if check(s) and check2(s):
		print('Yes')
		return
	elif check2(s):
		print('Yes')
		return
	print('No')
func()


n = int(int(input()))
s = input()
if len(s) == 0:
	print('Yes')
elif s.count('(') != s.count(')'):
	print('No')
else:
	left = 0
	right = 0
	c = 0
	for i in s:
		if i == '(':
			left += 1
		elif left > 0:
			left -= 1
		else:
			c += 1
	if left == 0 and c == 0:
		print('Yes')
	elif left == 1 and c == 1:
		print('Yes')
	else:
		print('No')


n = int(input())
s = input()
br = 0
br_close = 0
flag = True
i = 0
if n % 2 == 1:
	flag = False
while i < n and flag:
	if s[i] == '(':
		br += 1
	elif s[i] == ')':
		br -= 1
	if br + 1 < 0 and flag:
		flag = False
	i += 1
if flag and br == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
l = []
for i in s:
	if len(l) > 0 and i == ')' and (l[-1] == '('):
		l.pop()
	else:
		l.append(i)
if len(l) == 2 and '(' in l and (')' in l) or len(l) == 0:
	print('Yes')
else:
	print('No')


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	s = input().rstrip()
	t = [0] * n
	first = -1
	for (i, c) in enumerate(s):
		if i > 0:
			t[i] += t[i - 1]
		t[i] += 1 if c == '(' else -1
		if t[i] < 0 and first == -1:
			first = i
	if first == -1:
		if t[n - 1] == 0:
			print('Yes')
		else:
			print('No')
	else:
		t = [0] * n
		for i in range(first + 1, n):
			t[i] += t[i - 1]
			t[i] += 1 if s[i] == '(' else -1
			if t[i] < 0:
				print('No')
				return
		if t[n - 1] == 1:
			print('Yes')
		else:
			print('No')
main()


n = int(input())
s = input()
stk = []
for i in range(n):
	if len(stk) > 0 and s[i] == ')':
		if stk[-1] == ')':
			stk.append(')')
		else:
			stk.pop(-1)
	else:
		stk.append(s[i])
ans = 'No'
if len(stk) == 2:
	stk.sort()
	if stk == ['(', ')']:
		ans = 'Yes'
elif len(stk) == 0:
	ans = 'Yes'
print(ans)


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	print('No')
	exit()
stk = []
karma = 0
f = 1
ans = 1
for i in s:
	if i == '(':
		stk.append(i)
	elif not stk:
		f = 0
		if not karma:
			karma = 1
		else:
			ans = 0
			break
	else:
		stk.pop()
if ans and len(stk) == 1 and (stk[0] == '('):
	print('Yes')
	exit()
if not stk and f:
	f = 1
if f:
	print('Yes')
	exit()
if not ans:
	print('No')
	exit()


n = int(input())
s = input()
count = 0
res = ''
for i in s:
	if i == '(':
		count += 1
	else:
		count -= 1
	if count < -1:
		res = 'No'
		break
if res == '':
	if count == 0:
		res = 'Yes'
	else:
		res = 'No'
print(res)


n = int(input())
a = str(input())
q = 0
w = 0
i = 0
while i < n:
	if a[i] == '(':
		q += 1
	else:
		w += 1
	if w > q + 1:
		break
	else:
		i += 1
if i == n and w == q:
	print('Yes')
else:
	print('No')


from sys import setcheckinterval, stdin
setcheckinterval(1000)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
n = iin()
s = list(input())
ch1 = s.count('(')
if ch1 == n - ch1:
	a = []
	for i in range(n):
		if a:
			if s[i] == ')' and a[-1] == '(':
				a.pop()
			else:
				a.append(s[i])
		else:
			a.append(s[i])
	if len(a) == 2 or not a:
		print('Yes')
		exit()
print('No')


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
else:
	bal = 0
	for i in range(n):
		if s[i] == '(':
			bal += 1
		else:
			bal -= 1
	if bal != 0:
		print('No')
	else:
		st = []
		for c in s:
			if c == '(':
				st.append(c)
			elif len(st) > 0:
				st.pop()
		if len(st) <= 1:
			print('Yes')
		else:
			print('No')


n = int(input())
l = input()
l = list(l)

def func(l):
	stack = [0]
	for i in l:
		if i == '(':
			stack.append(i)
		elif i == ')' and stack[-1] == 0:
			stack.append(')')
		elif i == ')' and stack[-1] == '(':
			del stack[-1]
		else:
			stack.append(i)
	return stack
newl = func(l)
if len(newl) == 1:
	print('Yes')
elif len(newl) == 3:
	if newl[1] != newl[2]:
		print('Yes')
	else:
		print('No')
else:
	print('No')


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)

def output(answer):
	stdout.write(str(answer) + '\n')
n = int(z())
arr = fast()
if n % 2:
	print('NO')
	exit()
que = 0
b1 = 0
b2 = 0
for i in arr:
	if i == '(':
		que += 1
		b1 += 1
	else:
		que -= 1
		b2 += 1
	if que <= -2:
		print('NO')
		exit()
if que:
	print('NO')
else:
	print('YES')


import sys
import collections
import functools
n = int(input().strip())
s = input().strip()
(stack, s2) = ([], [])
for i in s:
	if i == '(':
		stack.append(i)
	elif i == ')' and stack and (stack[-1] == '('):
		stack.pop()
	else:
		s2.append(i)
if len(s2) == 1 and s2[-1] == ')' and (len(stack) == 1) and (stack[-1] == '('):
	print('Yes')
elif len(s2) == 0 and len(stack) == 0:
	print('Yes')
else:
	print('No')


n = int(input())
q = input()
l = 0
p = 0
for i in range(len(q)):
	if q[i] == ')':
		if p > 0:
			p -= 1
		else:
			l += 1
	if q[i] == '(':
		p += 1
if p == l and p < 2:
	print('Yes')
else:
	print('No')


n = int(input())
S = input()
Stack = [S[0]]
for i in range(1, n):
	if len(Stack) == 0:
		Stack.append(S[i])
	elif Stack[-1] + S[i] == '()':
		del Stack[-1]
	else:
		Stack.append(S[i])
if len(Stack) == 0:
	print('Yes')
elif len(Stack) == 1:
	print('No')
elif Stack[0] == ')' and Stack[1] == '(' and (len(Stack) == 2):
	print('Yes')
else:
	print('No')


n = int(input())
S = input()
cnt = 0
if S.count('(') != S.count(')'):
	print('No')
	exit()
for i in range(n):
	if S[i] == '(':
		cnt += 1
	elif S[i] == ')':
		cnt -= 1
	if cnt <= -2:
		print('No')
		break
else:
	print('Yes')


import sys
n = int(input())
s = input().strip()
if n % 2 == 1:
	print('No')
	sys.exit()
sum_bracket = 0
for i in s:
	if i == ')':
		sum_bracket -= 1
	if i == '(':
		sum_bracket += 1
	if sum_bracket < -1:
		print('No')
		sys.exit(0)
if sum_bracket == 0:
	print('Yes')
else:
	print('No')


for t in range(1):
	n = int(input())
	arr = list(input())
	counter = 0
	gb_counter = 0
	if n % 2 == 1:
		print('No')
		continue
	for i in arr:
		if i == ')':
			counter -= 1
		else:
			counter += 1
		gb_counter = min(gb_counter, counter)
	if gb_counter >= -1 and counter == 0:
		print('Yes')
	else:
		print('No')


from itertools import accumulate
n = int(input())
s = [1 if c == '(' else -1 for c in input()]
res = sum(s) == 0
if res:
	l = [*accumulate(s)]
	m = min(l)
	res &= m >= -1
print('Yes' if res else 'No')


n = int(input())
m = input()
m = list(m)
if n % 2 == 0:
	d = 0
	for i in range(n):
		if m[i] == '(':
			d += 1
		if m[i] == ')':
			d -= 1
			if d < -1:
				d -= 400001
	if d == 0:
		print('Yes')
	else:
		print('No')
else:
	print('No')


n = int(input())
s = input().strip()
stc = []
(open, close) = (0, 0)
for i in s:
	if i == '(':
		open += 1
		stc.append(i)
	else:
		close += 1
		if stc:
			stc.pop()
if open == close and len(stc) < 2:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
t = 0
for i in s:
	if i == '(':
		t += 1
	else:
		t -= 1
	if t < -1:
		print('No')
		exit()
if t == 0:
	print('Yes')
else:
	print('No')


def funcc(n, s):
	cnt = 0
	i = 0
	if n % 2 != 0:
		return 'No'
	else:
		while i < n:
			if s[i] == '(':
				cnt += 1
			else:
				cnt -= 1
			if cnt < -1:
				break
			i += 1
	if cnt == 0:
		return 'Yes'
	else:
		return 'No'
n = int(input())
s = str(input())
print(funcc(n, s))


a = int(input())
b = str(input())
k = 0
for i in b:
	if i == '(':
		k += 1
	else:
		k -= 1
	if k < -1:
		print('NO')
		exit()
if k == 0:
	print('YES')
else:
	print('NO')


from sys import stdin
n = int(stdin.readline().strip())
s = list(stdin.readline().strip())
dp1 = [0 for i in range(n)]
dp2 = [0 for i in range(n)]
x = -1
y = -1
for i in range(n):
	if s[i] == '(':
		dp1[i] += 1
	else:
		dp1[i] -= 1
	if i > 0:
		dp1[i] += dp1[i - 1]
for i in range(n - 1, -1, -1):
	if s[i] == '(':
		dp2[i] += 1
	else:
		dp2[i] -= 1
	if i < n - 1:
		dp2[i] += dp2[i + 1]
flag = True
mn = min(dp1)
mx = max(dp2)
if mn >= -1 and mx <= 1 and (dp1[-1] == 2 or dp1[-1] == -2 or dp1[-1] == 0):
	print('Yes')
else:
	print('No')


n = int(input())
strr = input()

def solve(strr):
	open_stack = []
	close_stack = []
	for ele in strr:
		if ele == '(':
			open_stack.append('(')
		elif open_stack:
			open_stack.pop()
		else:
			close_stack.append(')')
	return len(open_stack) == 0 and len(close_stack) == 0 or (len(open_stack) == 1 and len(close_stack) == 1)
print('Yes' if solve(strr) else 'No')


def authors(n, s):
	b = 0
	if n % 2 == 0:
		ans = True
		for i in s:
			if i == '(':
				b -= 1
			else:
				b += 1
			if b > 1:
				ans = False
				break
		if b < 0:
			ans = False
	else:
		ans = False
	return ans
n = int(input())
s = input()
if authors(n, s):
	print('Yes')
else:
	print('No')


n = int(input())
x = input()
c = 0
a = x.count('(')
b = x.count(')')
if a == b:
	if n == 1:
		print('No')
	else:
		for i in range(n):
			if c >= -1:
				if x[i] == '(':
					c = c + 1
				else:
					c = c - 1
				if i == n - 1:
					print('Yes')
			elif i == n - 1:
				print('No')
else:
	print('No')


n = int(input())
s = input()
cur = 0
for ch in s:
	if ch == '(':
		cur += 1
	else:
		cur -= 1
	if cur == -2:
		print('No')
		return
print('Yes' if cur == 0 else 'No')


n = int(input())
s = input()
opening_brackets = 0
closing_brackets = 0
answer_no = False
for ch in s:
	if ch == '(':
		opening_brackets += 1
	elif opening_brackets > 0:
		opening_brackets -= 1
	elif closing_brackets == 0:
		closing_brackets = 1
	else:
		answer_no = True
		break
if answer_no:
	print('No')
elif opening_brackets == 1 and closing_brackets == 1:
	print('Yes')
elif opening_brackets > 0 or closing_brackets > 0:
	print('No')
else:
	print('Yes')


n = int(input())
brackets = list(input())
count = 0
matches = 0
for i in brackets:
	if i == '(':
		count += 1
	else:
		count -= 1
	matches = min(matches, count)
print('Yes' if matches >= -1 and count == 0 else 'No')


a = int(input())
b = input()
j = 0
if a % 2 == 0:
	for c in b:
		if c == '(':
			j += 1
		else:
			j -= 1
		if j < -1:
			break
	if j != 0:
		print('No')
	else:
		print('Yes')
else:
	print('No')


n = int(input())
s = input()
c_op = 0
er = 0
if n % 2 != 0:
	print('No')
	exit()
for i in s:
	if i == '(':
		c_op += 1
	if i == ')' and c_op > 0:
		c_op -= 1
	elif i == ')' and c_op == 0:
		er += 1
if er == 0 and c_op == 0 or (er == 1 and c_op == 1):
	print('Yes')
else:
	print('No')


from collections import defaultdict

def main():
	n = int(input())
	dados = input()
	if n % 2 != 0:
		print('No', end='')
		exit()
	qtds = defaultdict(int)
	for x in dados:
		qtds[x] += 1
		if qtds[')'] - qtds['('] >= 2:
			print('No', end='')
			exit()
	if qtds[')'] - qtds['('] != 0:
		print('No', end='')
	else:
		print('Yes', end='')
main()


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
	exit()
top = 0
cntl = 0
cntr = 0
for c in s:
	if c == '(':
		top += 1
		cntl += 1
	else:
		top = max(top - 1, 0)
		cntr += 1
if top <= 1 and cntl == cntr:
	print('Yes')
else:
	print('No')


from collections import deque
n = int(input())
brackets = input()
stack = deque()
for i in range(len(brackets)):
	if not stack:
		stack.append(brackets[i])
	elif stack:
		if brackets[i] == ')' and stack[-1] == '(':
			stack.pop()
		else:
			stack.append(brackets[i])
b = stack.count(')')
f = stack.count('(')
if b == 1 and f == 1 or not stack:
	print('Yes')
else:
	print('No')


a = int(input())
b = input()
if b.count('(') != b.count(')'):
	print('NO')
else:
	t = 0
	for y in range(a):
		if b[y] == ')':
			t -= 1
		else:
			t += 1
		if t < -1:
			break
	if t < -1:
		print('NO')
	else:
		print('YES')


from collections import Counter
n = int(input())
s = input()
count = 0
c = Counter(s)
if c[')'] != c['(']:
	print('No')
else:
	for char in s:
		if char == ')':
			count -= 1
			if count == -2:
				print('No')
				break
		else:
			count += 1
	else:
		print('Yes')


n = int(input())
s = input()
c = 0
r = 0
for i in range(len(s)):
	if s[i] == '(':
		c += 1
	else:
		c -= 1
	if c < -1:
		r = 1
		print('No')
		break
if r != 1 and c == 0:
	print('Yes')
elif r != 1:
	print('No')


n = int(input())
s = input()
x = y = 0
l = 0
ll = 0
if n % 2 != 0:
	print('No')
else:
	for i in range(n):
		if s[i] == '(':
			x += 1
			l += 1
		else:
			if l == 0:
				ll += 1
			else:
				l -= 1
			y += 1
	if n // 2 != x:
		print('No')
	elif ll > 1:
		print('No')
	elif ll == 1 and l == 1:
		print('Yes')
	else:
		print('Yes')


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
s = input()
ss = []
cnt = 0
min_cnt = 10 ** 10
for i in range(n):
	if s[i] == '(':
		ss.append(1)
		cnt += 1
	else:
		ss.append(-1)
		cnt += -1
	min_cnt = min(min_cnt, cnt)
if cnt != 0 or min_cnt < -1:
	print('No')
else:
	print('Yes')


t = int(input())
s = input('')
n = 0
m = 0
l = 0
q = 0
w = 0
for i in range(0, t):
	if s[i] == '(':
		n += 1
		q += 1
	else:
		w += 1
		m += 1
	if w > q:
		w -= 1
		l += 1
if l > 1 or n != m:
	print('NO')
else:
	print('YES')


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	exit(print('NO'))
cs = 0
f = 0
for i in s:
	if i == '(':
		cs += 1
	else:
		cs -= 1
	if cs < 0:
		if f:
			exit(print('NO'))
		f = 1
		cs = 0
print('YES')


n = int(input())
s = input()
if n % 2:
	print('NO')
else:
	close = 0
	open = 0
	res = []
	for i in range(n):
		if s[i] == '(':
			res.append(s[i])
		elif s[i] == ')':
			if len(res) > 0 and res[-1] == '(':
				res.pop()
			else:
				res.append(s[i])
	if len(res) == 0 or (len(res) == 2 and res == [')', '(']):
		print('Yes')
	else:
		print('No')


n = int(input())
s = input()
l = list()
cnt = 0
flag = 0
tim = 0
for i in range(len(s)):
	if s[i] == '(':
		l.append(s[i])
		cnt += 1
	elif cnt == 0:
		l.append(s[i])
		cnt += 1
		flag = 1
	elif l[len(l) - 1] == '(':
		l.pop()
		cnt = cnt - 1
	elif l[len(l) - 1] == ')' or flag == 1:
		print('No')
		tim = 1
		break
	elif flag == 0:
		l.append(s[i])
		cnt += 1
		flag = 1
if tim == 0:
	if len(l) == 0:
		print('Yes')
	else:
		cl = 0
		cr = 0
		for i in l:
			if i == ')':
				cl += 1
			else:
				cr += 1
		if cl == 1 and cr == 1:
			print('Yes')
		else:
			print('No')


n = int(input())
line = input()
stack = []
count = 0
for i in range(n):
	if line[i] == '(':
		stack.append(line[i])
	elif line[i] == ')':
		if len(stack) == 0:
			count += 1
		else:
			stack.pop()
if count != len(stack):
	print('No')
elif count <= 1:
	print('Yes')
else:
	print('No')


import sys
n = int(input())
s = input()
j = 0
for i in s:
	if i == '(':
		j = j + 1
	else:
		j = j - 1
	if j < -1:
		print('No')
		sys.exit()
if j == 0:
	print('Yes')
else:
	print('No')


def is_correct(s):
	cumsum = 0
	for k in s:
		if k == '(':
			cumsum += 1
		elif k == ')':
			cumsum -= 1
		if cumsum == -2:
			return False
	return cumsum == 0
input()
if is_correct(input()):
	print('Yes')
else:
	print('No')


n = int(input())
S = input()
excess = 0
open = 0
for c in S:
	if c == '(':
		open += 1
	elif open == 0:
		excess += 1
	else:
		open -= 1
if open == 0 and excess == 0:
	print('Yes')
elif open == 1 and excess == 1:
	print('Yes')
else:
	print('No')


stack = []
N = int(input())
arr = input()
for j in range(N):
	stack.append(arr[j])
	if len(stack) > 1:
		a = stack.pop()
		b = stack.pop()
		if a == ')' and b == '(':
			continue
		else:
			stack.append(b)
			stack.append(a)
if len(stack) == 0:
	print('Yes')
elif len(stack) == 2 and stack[0] == ')' and (stack[1] == '('):
	print('Yes')
else:
	print('No')


n = int(input())
q = 0
e = False
for elem in input():
	if elem == '(':
		q += 1
	elif elem == ')':
		if q > 0:
			q -= 1
		elif q == 0 and (not e):
			e = True
		else:
			break
if q == 1 and e or (not q and (not e)):
	print('YES')
else:
	print('NO')


n = int(input())
line = input()
bal = 0
res = 1
first_error = 0
for i in line:
	if i == '(':
		bal += 1
		if bal == 0:
			first_error = 0
	elif i == ')':
		bal -= 1
		if bal < 0 and first_error == 0:
			first_error = 1
		elif bal < 0 and first_error == 1:
			res = 0
	if bal < -1:
		break
if bal != 0:
	res = 0
if res == 1:
	print('Yes')
if res == 0:
	print('No')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		s = rs()
		ans = 'No'
		if n % 2 == 0:
			depth = 0
			t = 0
			ans = 'Yes'
			for i in range(n):
				if s[i] == '(':
					depth += 1
				else:
					depth -= 1
				if depth < -1:
					ans = 'No'
					break
			if depth > 1:
				ans = 'No'
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
s = input()
left = 0
depth = 0
used = False
ok = True
for c in s:
	if c == '(':
		left += 1
		depth += 1
	else:
		depth -= 1
		if depth == -1 and (not used):
			depth = 0
			used = True
		if depth < 0 and used:
			print('No')
			ok = False
			break
if ok:
	if left == n - left:
		print('Yes')
	else:
		print('No')


input()
x = 0
for y in input():
	if '(' == y:
		x += 1
	else:
		x -= 1
		if x < -1:
			print('No')
			break
else:
	if x:
		print('No')
	else:
		print('Yes')


List = [' ']
n = int(input())
Read = input()
for i in range(n):
	List.append(Read[i])
Cnto = [0]
Cntc = [0]
for i in range(1, n + 1):
	Cnto.append(0)
	Cntc.append(0)
	Cnto[i] = Cnto[i - 1] + (List[i] == '(')
	Cntc[i] = Cntc[i - 1] + (List[i] == ')')
chk = 0
if Cntc[n] == Cnto[n]:
	chk = 1
id = 1
for i in range(1, n + 1):
	if Cnto[i] < Cntc[i]:
		id = i
		break
List2 = []
if List[id] == '(':
	List2.append('(')
	for i in range(1, n + 1):
		if i != id:
			List2.append(List[i])
else:
	for i in range(1, n + 1):
		if i != id:
			List2.append(List[i])
	List2.append(')')
chk2 = 1
for i in range(1, n + 1):
	Cnto[i] = Cnto[i - 1] + (List2[i - 1] == '(')
	Cntc[i] = Cntc[i - 1] + (List2[i - 1] == ')')
	if Cnto[i] < Cntc[i]:
		chk2 = 0
if chk and chk2:
	print('Yes')
else:
	print('No')


input()
inp = input()
st = []
(fe, se) = (0, 0)
for i in inp:
	if i == '(':
		st.append(0)
	elif i == ')':
		if st:
			st.pop()
		else:
			fe += 1
if st:
	se = len(st)
if fe == se and fe < 2:
	print('Yes')
else:
	print('No')


x = int(input())
n = input()
if x % 2 == 1:
	print('NO')
else:
	a = []
	b = 0
	for i in n:
		if i == ')':
			if len(a) > 0 and a[-1] == '(':
				a.pop()
			else:
				a.append(i)
		else:
			a.append(i)
	if len(a) == 0:
		print('YES')
	else:
		c = 0
		d = 0
		for i in a:
			if i == ')':
				c += 1
			else:
				d += 1
		if c == 1 and d == 1:
			print('YES')
		else:
			print('NO')


n = int(input())
s = input()
st = []
for i in s:
	if st == []:
		st.append(i)
	elif st[-1] == '(' and i == ')':
		st.pop()
	else:
		st.append(i)
if st == [] or st == [')', '(']:
	print('Yes')
else:
	print('No')


def get_can_be_corrected(seq):
	if len(seq) % 2:
		return 'No'
	cntr = 0
	for b in seq:
		if b == ')':
			cntr -= 1
		else:
			cntr += 1
		if cntr == -2:
			return 'No'
	return 'Yes' if cntr == 0 else 'No'
input()
print(get_can_be_corrected(input()))


n = int(input())
s = str(input())
op = 0
cl = 0
b = 0
for c in s:
	if c == '(':
		op += 1
	if c == ')':
		if op > 0:
			op -= 1
		else:
			b += 1
if b == 1 and op == 1 or (b == 0 and op == 0):
	print('Yes')
else:
	print('No')


I = input
num = int(I())
if num % 2 == 1:
	print('NO')
	exit()
count = 1
my_list = []
my_string = I()
for i in my_string:
	if i == '(':
		my_list.append(1)
	elif count == 0:
		if len(my_list) == 0:
			print('NO')
			exit()
		else:
			my_list.pop()
	else:
		count -= 1
if len(my_list) == 1:
	print('YES')
else:
	print('NO')


input()
k = 0
for ch in input():
	if ch == '(':
		k += 1
	elif k < 0:
		print('No')
		break
	else:
		k -= 1
else:
	print('No' if k else 'Yes')


def Bad_sequence(string):
	ls = []
	for s in string:
		if s == ')':
			if len(ls) == 0:
				ls.append(s)
			elif ls[-1] == ')':
				ls.append(s)
			else:
				ls.pop()
		else:
			ls.append(s)
	if len(ls) == 0 or (len(ls) == 2 and ls[0] == ')' and (ls[1] == '(')):
		print('Yes')
	else:
		print('No')
int_ = input()
brack_string = input()
Bad_sequence(brack_string)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	s = input()
	if s.count('(') != s.count(')'):
		print('No')
		continue
	total = 0
	mt = 0
	for i in s:
		if i == '(':
			total += 1
		else:
			total -= 1
		mt = min(total, mt)
	print('Yes' if mt >= -1 else 'No')


n = int(input())
s = input()
count = 0
fin = False
if s == '':
	print('Yes')
	exit()
elif n % 2 != 0:
	print('No')
	exit()
elif s[0] == ')' and s[1] == ')':
	print('No')
	exit()
else:
	for i in range(len(s)):
		if s[i] == '(':
			count += 1
		elif s[i] == ')':
			if count == 0:
				if s[i + 1] == ')':
					print('No')
					fin = True
					exit()
					break
			count -= 1
	if count == 0 and (not fin):
		print('Yes')
		exit()
	else:
		print('No')
		exit()


def mm(s):
	if s.count('(') != s.count(')'):
		return False
	t = []
	for i in range(len(s)):
		if t == []:
			t += s[i]
		elif t[-1] == '(' and s[i] == ')':
			t.pop()
		else:
			t += s[i]
	if t == [] or t == [')', '(']:
		return True
	return False
n = int(input())
s = input()
if n == 2:
	if s == '()' or s == ')(':
		print('Yes')
	else:
		print('No')
	exit(0)
if n & 1:
	print('No')
	exit(0)
if mm(s):
	print('Yes')
else:
	print('No')


import math
n = int(input())
s = input()
cl = 0
cr = 0
if len(s) % 2 == 1:
	print('No')
else:
	br = False
	for i in range(len(s)):
		if s[i] == '(':
			cl += 1
		else:
			cr += 1
		if cr - cl > 1:
			print('No')
			br = True
			break
	if not br:
		if abs(cl - cr) < 2:
			print('Yes')
		else:
			print('No')


import sys
import math
input = sys.stdin.readline
n = int(input())
s = list(input())
if s.count('(') == s.count(')'):
	op = 0
	cl = 0
	flag = True
	for i in range(n):
		if s[i] == '(':
			op += 1
		else:
			cl += 1
		if cl - op >= 2:
			print('No')
			flag = False
			break
	if flag:
		print('Yes')
else:
	print('No')


def run():
	n = eval(input())
	st = input()
	if n % 2 == 1:
		print('No')
		return
	stack = []
	for i in range(n):
		stack.append(st[i])
		if len(stack) >= 2:
			if stack[-1] == ')' and stack[-2] == '(':
				stack.pop()
				stack.pop()
	if len(stack) == 0 or ''.join(stack) == ')(':
		print('Yes')
	else:
		print('No')
run()


def solve():
	n = input()
	s = input()
	if int(n) % 2 == 1:
		return print('NO')
	open_bracket = 0
	unopened_bracket = 0
	for char in s:
		if char == '(':
			open_bracket += 1
		elif open_bracket > 0:
			open_bracket -= 1
		elif unopened_bracket < 1:
			unopened_bracket += 1
		else:
			return print('NO')
	open_bracket -= unopened_bracket
	print('YES' if open_bracket == 0 else 'NO')
solve()


n = int(input())
s = input()
(diff, ci) = ([], 0)
if s.count('(') != s.count(')'):
	print('No')
	exit()
for i in s:
	if i == '(':
		ci += 1
	else:
		ci -= 1
	diff.append(ci)
if min(diff) >= -1:
	print('Yes')
else:
	print('No')


def solution():
	from sys import stdout, stdin
	(_input, _print) = (stdin.readline, stdout.write)
	(_int, _range, _min, _max) = (int, range, min, max)
	n = int(input())
	arr = [1 if i == '(' else -1 for i in input()]
	if sum(arr) != 0:
		print('No')
	else:
		s = [0] * n
		for i in range(n):
			if i == 0:
				s[i] = arr[i]
			else:
				s[i] = arr[i] + s[i - 1]
				if s[i] == -2:
					print('No')
					break
		else:
			print('Yes')
solution()


from itertools import accumulate
n = int(input())
a = list(accumulate([1 if c == '(' else -1 for c in input()]))
print('No' if min(a) < -1 or a[-1] != 0 else 'Yes')


n = int(input())
s = input()
a = s.count('(')
b = s.count(')')
if a != b:
	print('NO')
else:
	e = 0
	t = True
	for i in range(n):
		if e <= -2:
			t = False
			break
		if s[i] == '(':
			e += 1
		else:
			e -= 1
	if t:
		print('YES')
	else:
		print('NO')


n = int(input())
(res, k) = (0, 0)
for (i, x) in enumerate(input()):
	if x == '(':
		res += 1
	else:
		res -= 1
	if res < -1:
		k = 1
		break
if k == 0:
	if res == 0:
		print('Yes')
	else:
		print('No')
else:
	print('No')


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if val % ll[mid] == 0:
			ans = ll[mid]
			return binary(l, mid - 1, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def odd(n, ans, s):
	if n % 2 != 0 or n in s:
		return ans
	else:
		s.add(n)
		return odd(n // 2, ans + 1, s)
t = int(input())
s = str(input())
stack = []
for i in range(t):
	if len(stack) == 0:
		stack.append(s[i:i + 1])
	elif stack[len(stack) - 1] == ')':
		stack.append(s[i:i + 1])
	elif s[i:i + 1] == '(':
		stack.append(s[i:i + 1])
	else:
		stack.pop()
if len(stack) == 0:
	print('YES')
elif len(stack) == 1 or len(stack) > 2:
	print('NO')
elif stack[0] == ')' and stack[1] == '(':
	print('YES')
else:
	print('NO')


input()
s = input()
ans = 1
cnt = 0
cha = 0
for x in s:
	if x == '(':
		cnt += 1
	else:
		cnt -= 1
	if cnt < 0:
		if cha == 0:
			cha = 1
			cnt += 1
		else:
			ans = 0
cnt -= cha
if cnt != 0:
	ans = 0
print('Yes' if ans else 'No')


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s)

def invr():
	return map(int, input().split())

def main():
	n = inp()
	s = insr()
	ans = 0
	for i in s:
		if i == '(':
			ans += 1
		elif i == ')':
			ans -= 1
		if ans < -1:
			print('No')
			break
	else:
		if ans == 0:
			print('Yes')
		else:
			print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
elif s.count('(') != s.count(')'):
	print('No')
else:
	count = 0
	flag = True
	for i in range(len(s)):
		if s[i] == '(':
			count += 1
		else:
			count -= 1
		if count < -1:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		print('No')


n = int(input())
s = list(input())
l = []
flag = 0
for i in range(0, len(s)):
	if len(l) == 0:
		l.append(s[i])
	elif l[-1] == '(' and s[i] == ')':
		l.pop()
	else:
		l.append(s[i])
if len(l) == 2:
	if l[0] != l[1]:
		print('Yes')
	else:
		print('No')
elif len(l) == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
y = []
for i in s:
	y.append(i)
if n % 2 == 0:
	stack = []
	i = 0
	f = 0
	while i < n:
		if y[i] == '(':
			stack.append(y[i])
		elif len(stack) != 0:
			stack.pop(-1)
		elif f == 0:
			y.append(')')
			n = n + 1
			f = 1
		else:
			f = 2
			break
		i += 1
	if f == 2:
		print('NO')
	elif len(stack) != 0:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


def solve(string):
	stack = []
	errors = 0
	for c in string:
		if c == '(':
			stack.append('(')
			continue
		try:
			del stack[-1]
		except IndexError:
			errors += 1
	if errors <= 1 and len(stack) == errors:
		print('Yes')
		return
	print('No')
n = int(input())
sequence = input()
solve(sequence)


N = int(input())
S = list(input())
lnum = len([x for x in S if x == '('])
rnum = len([x for x in S if x == ')'])
if lnum != rnum:
	print('No')
	exit()
lcnt = 0
rcnt = 0
for x in S:
	if x == '(':
		lcnt += 1
	elif lcnt > 0:
		lcnt -= 1
	else:
		rcnt += 1
if rcnt > 1:
	print('No')
else:
	print('Yes')


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = input()
s = []
for i in a:
	if s and i == ')':
		if s[-1] == '(':
			s.pop(-1)
		else:
			s.append(')')
	else:
		s.append(i)
if len(s) == 0:
	print('YES')
elif len(s) != 2:
	print('NO')
else:
	he = ('(' in s) + (')' in s)
	if he == 2 or he == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
s = input()
parenteses = {')': 0, '(': 0}
acabou = False
if n % 2 != 0:
	print('No')
	acabou = True
if not acabou:
	for simbolo in s:
		parenteses[simbolo] += 1
		if parenteses[')'] - parenteses['('] > 1:
			print('No')
			acabou = True
			exit()
	if not acabou:
		if parenteses[')'] - parenteses['('] != 0:
			print('No')
		else:
			print('Yes')


n = int(input())
s = input()
(c1, c2) = (0, 0)
c = 1
for i in range(n):
	if s[i] == '(':
		c1 += 1
	else:
		c1 -= 1
	c2 = min(c2, c1)
	if c2 < -1:
		c = 0
		break
if c == 1 and c1 == 0:
	print('YES')
else:
	print('NO')


n = int(input())
a = input()
bh = 0
for i in a:
	if i == '(':
		bh = bh + 1
	else:
		bh = bh - 1
		if bh < -1:
			break
if bh == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
l = 0
a = 0
b = 0
count = 0
flag = True
if n % 2 != 0:
	print('No')
else:
	for i in s:
		if count >= 2:
			flag = False
			break
		if i == '(':
			l += 1
			a += 1
		elif l > 0:
			l -= 1
			b += 1
		else:
			count += 1
			b += 1
	if count <= 1 and a == b and flag:
		print('Yes')
	else:
		print('No')


n = int(input())
s = input()
l = 0
r = 0
dif = [0 for i in range(n)]
ans = 'No'
neg = 0
for i in range(n):
	if s[i] == '(':
		l += 1
		if i != 0:
			dif[i] = dif[i - 1] + 1
		else:
			dif[i] = 1
		if dif[i] < 0:
			neg += 1
	else:
		r += 1
		if i != 0:
			dif[i] = dif[i - 1] - 1
		else:
			dif[0] = -1
		if dif[i] < 0:
			neg += 1
if abs(l - r) != 0 or n % 2 != 0:
	print('No')
elif neg == 2 and min(dif) == -1:
	print('Yes')
elif min(dif) < -1:
	print('No')
else:
	print('Yes')


n = int(input())
s = input()
t = 0
if n % 2:
	print('No')
	exit()
else:
	for c in s:
		if c == '(':
			t += 1
		else:
			t -= 1
		if t < -1:
			print('No')
			exit()
print('Yes' if t == 0 else 'No')


from collections import deque
s = deque()
input()
n = input()

def do(s, n):
	flag = False
	for b in n:
		if b == '(':
			s.append(b)
		elif len(s) <= 0:
			if not flag:
				flag = True
			else:
				return False
		else:
			s.pop()
	if len(s) == 1 and flag or (len(s) == 0 and (not flag)):
		return True
	return False
if do(s, n):
	print('Yes')
else:
	print('No')


from sys import *
from math import *
from collections import Counter
fi = lambda : stdin.readline()
n = int(fi())
s = fi().strip('\n')
if s.count('(') != s.count(')'):
	print('No')
else:
	a = 0
	b = 0
	for i in range(n):
		if a == 0 and s[i] == ')':
			b += 1
		elif s[i] == '(':
			a += 1
		elif s[i] == ')':
			a -= 1
	if a + b == 2 or (a == 0 and b == 0):
		print('Yes')
	else:
		print('No')


import sys
n = int(input())
s = str(input())
if n % 2 == 1:
	print('No')
	sys.exit()
k = 0
(g, gg) = (0, 0)
for i in range(n):
	if s[i] == '(':
		k += 1
		g += 1
	else:
		k -= 1
		gg += 1
	if k <= -2:
		print('No')
		sys.exit()
if g != gg:
	print('No')
	sys.exit()
elif k <= 2:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	print('NO')
else:
	ans = []
	stack = []
	for i in s:
		if i == '(':
			stack.append('(')
		elif stack == []:
			ans.append(')')
		else:
			stack.pop()
	if stack == []:
		print('YES')
	elif len(stack) == 1 and len(ans) == 1:
		print('YES')
	else:
		print('NO')


def do():
	n = int(input())
	s = input()
	diff = 0
	used = False
	for c in s:
		if c == '(':
			diff += 1
		else:
			diff -= 1
		if diff < 0:
			if used:
				return 'NO'
			used = True
			diff += 1
	if not used and diff == 0:
		return 'YES'
	if used and diff == 1:
		return 'YES'
	return 'NO'
print(do())


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

def ssinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def nninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
n = iinp()
s = ssinp()
if n % 2 == 1:
	print('No')
else:
	left = right = tot = 0
	f = 0
	for c in s:
		if right - left == 2:
			print('No')
			f = 1
			break
		elif c == '(':
			left += 1
		elif left > 0:
			tot += 1
			left -= 1
		else:
			right += 1
	if f == 0:
		if left == 1 and right == 1:
			print('Yes')
		elif left == 0 and right == 0:
			print('Yes')
		else:
			print('No')


n = int(input())
s = input()
if n % 2 == 0:
	k = '('
	k = k + s + ')'
	d = []
	xx = 0
	for i in range(len(k)):
		if k[i] == '(':
			d.append('(')
		elif len(d) != 0:
			d.pop()
		else:
			xx = 1
			print('No')
			break
	if xx == 0:
		if len(d) == 0:
			print('Yes')
		else:
			print('No')
else:
	print('No')


n = int(input())
s = input()
o = 0
for i in s:
	if i == '(':
		o += 1
	else:
		o -= 1
		if o < -1:
			break
if o == 0:
	print('Yes')
else:
	print('No')


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
arr = []
s = input()
for i in s:
	if not arr:
		arr.append(i)
		continue
	if i == '(' and arr[-1] == '(':
		arr.append(i)
	elif i == '(' and arr[-1] == ')':
		arr.append(i)
	elif i == ')' and arr[-1] == '(':
		arr.pop()
	elif i == ')' and arr[-1] == ')':
		print('No')
		exit()
if len(arr) == 2 and arr[0] == ')' and (arr[1] == '(') or len(arr) == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
a = 0
b = 0
if n % 2 == 1:
	print('No')
else:
	for i in s:
		if i == '(':
			a += 1
		if i == ')':
			a -= 1
		if a == -2:
			b = 10
			break
	if a == 0:
		if b == 10:
			print('No')
		else:
			print('Yes')
	else:
		print('No')


n = int(input())
s = input()
L = []
c1 = 0
c2 = 0
for i in range(0, len(s)):
	L.append(s[i])
	if s[i] == '(':
		c1 += 1
	else:
		c2 += 1
flag = 0
if L[0] == ')':
	L = L[1:]
	L.append(')')
	flag = 1
elif L[-1] == '(':
	L = ['('] + L
	L = L[:len(L) - 1]
	flag = 1
temp = 0
stk = []
for i in range(0, len(L)):
	if len(stk) == 0:
		if L[i] == ')':
			flag += 1
			temp = 1
		else:
			stk.append(L[i])
	elif stk[-1] == '(' and L[i] == ')':
		stk.pop()
	else:
		stk.append(L[i])
if temp == 1 and stk == ['(']:
	stk.pop()
if len(stk) == 0 and c1 == c2 and (n % 2 == 0) and (flag < 2):
	print('Yes')
else:
	print('No')


t = int(input())
n = input()
a = []
for i in range(0, len(n)):
	if n[i] == '(':
		a.append('(')
	if n[i] == ')':
		if len(a) == 0:
			a.append(')')
		elif a[len(a) - 1] == '(':
			a.pop(len(a) - 1)
		else:
			a.append(')')
if len(a) == 0:
	print('Yes')
else:
	p = a.count('(')
	q = a.count(')')
	if p == 1 and q == 1:
		print('Yes')
	else:
		print('No')


def countbrackets(string):
	if string.replace('(', '').replace(')', ''):
		return None
	string = [x == '(' for x in string]
	(bopen, extraclose) = (0, 0)
	for x in string:
		if x:
			bopen += 1
		elif bopen == 0:
			extraclose += 1
		else:
			bopen -= 1
	return (bopen, extraclose)
input()
bstring = input()
ans = countbrackets(bstring)
if ans == (1, 1) or ans == (0, 0):
	print('Yes')
else:
	print('No')


(_, string) = (input(), input())
stack = []
errors = 0
for i in range(len(string)):
	if string[i] is ')':
		if len(stack) > 0:
			stack.pop()
		else:
			errors += 1
	else:
		stack.append(1)
if errors == 1 and len(stack) == 1 or (errors == 0 and len(stack) == 0):
	print('Yes')
else:
	print('No')


def seqcheck(seq):
	if len(seq) % 2 == 1:
		return 'NO'
	li = 'YES'
	ct = 0
	a = 0
	b = 0
	arr = []
	curs = 0
	for i in seq:
		if i == '(':
			arr.append(1)
			a = a + 1
			curs = curs + 1
		else:
			arr.append(-1)
			b = b + 1
			curs = curs - 1
		if a < b:
			if ct == 0:
				ct = ct + 1
			elif curs < -1:
				ct = ct + 1
		if ct > 1:
			li = 'NO'
			break
	if a != b:
		li = 'NO'
	return li
n = int(input())
li = input()
print(seqcheck(li))


from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def A():
	(n, d, e) = IR(3)
	e *= 5
	ans = n
	m = n // e
	for i in range(m + 1):
		ans = min(ans, n - d * (n // d))
		n -= e
	print(ans)
	return

def B():
	(b, g, n) = IR(3)
	(b, g) = (min(b, g), max(b, g))
	if n <= b:
		print(n + 1)
	elif n <= g:
		print(b + 1)
	else:
		print(abs(n - b - g) + 1)
	return

def C():
	n = I()
	s = S()
	if n % 2:
		print('No')
		return
	q = deque()
	for i in s:
		if i == ')':
			if q and q[-1] == '(':
				q.pop()
			else:
				q.append(i)
		else:
			q.append(i)
	if len(q) == 2:
		if q[0] != q[1]:
			print('Yes')
		else:
			print('No')
	elif not q:
		print('Yes')
	else:
		print('No')
	return

def D():
	return

def E():
	return

def F():
	return

def G():
	return

def H():
	return
C()


n = int(input())
string = input().strip()
if string.count(')') == n / 2 and string.count(')') == n / 2:
	alist = []
	for i in string:
		if i == '(':
			alist.append(i)
		elif len(alist) == 0:
			alist.append(i)
		elif alist[-1] == '(':
			alist.pop()
		else:
			alist.append(i)
	gstring = ''.join(alist)
	if len(gstring) == 0:
		print('Yes')
	else:
		count = 0
		for i in range(len(gstring) // 2):
			if gstring[i] == '(' and gstring[n - i - 1] == ')':
				pass
			else:
				count += 1
		if count > 1:
			print('No')
		else:
			print('Yes')
else:
	print('No')


input()
t = 0
a = 0
for i in input():
	if i == ')':
		t -= 1
	if i == '(':
		t += 1
	if t == -1:
		if a == -1:
			break
		else:
			t = 0
			a = -1
if t == -1:
	print('NO')
elif t or a:
	if t:
		if t + a == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('YES')


len = int(input())
s = input()
st = neg = 0
for i in s:
	if i == '(':
		st += 1
	else:
		st -= 1
	neg = min(neg, st)
if st != 0 or neg < -1:
	print('No')
else:
	print('Yes')


n = int(input())
sk = input()
st = 0
if n % 2 == 1:
	print('No')
else:
	k = 0
	for el in sk:
		if el == ')':
			st += 1
		elif el == '(':
			st -= 1
		if st >= 2:
			print('No')
			k = 1
			break
	if k == 0:
		if abs(st) > 1:
			print('No')
		else:
			print('Yes')


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))
n = I1()
s = input()
stack = list()
t = 0
f = False
res = 'Yes'
for i in range(n):
	if s[i] == '(':
		stack.append(1)
		t += 1
	elif t == 0:
		if f == False:
			f = True
		else:
			res = 'No'
			break
	else:
		stack.pop()
		t -= 1
if res == 'Yes':
	if f == False and t == 0:
		print(res)
	elif f == False and t != 0:
		print('No')
	elif f == True and t == 0:
		print('No')
	elif f == True and t == 1:
		print(res)
	else:
		print('No')
else:
	print(res)


n = int(input())
string = input()
counter = 0
k = 1
for i in string:
	if i == '(':
		counter += 1
	else:
		counter -= 1
	if counter < -1:
		k = 0
		break
if counter == 0:
	print('Yes')
elif k == 0:
	print('No')
else:
	print('No')


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
s = si()
c = 0
for i in s:
	if i == '(':
		c += 1
	else:
		c -= 1
	if c <= -2:
		print('No')
		exit()
if c == 0:
	print('Yes')
else:
	print('No')


n = int(input())
string = input().strip()
count = 0
for i in string:
	if i == '(':
		count += 1
	else:
		count -= 1
	if count < -1:
		break
a = string.count('(') == string.count(')')
if count >= -1 and a:
	print('YES')
else:
	print('NO')


n = int(input())
a = [str(i) for i in input()]
b = []
x = 0
if n % 2 != 0:
	print('No')
	exit(0)
for i in range(0, n):
	if a[i] == '(':
		b.append('(')
	if a[i] == ')':
		if len(b) > 0:
			b.pop()
		else:
			x += 1
if x > 1 or len(b) > 1:
	print('No')
else:
	print('Yes')


def solve():
	n = int(input())
	s = input()
	op = 0
	cl = 0
	stack = []
	for i in s:
		op += int(i == '(')
		cl += int(i == ')')
		if len(stack) == 0:
			stack.append(i)
		elif stack[-1] == '(' and i == ')':
			stack.pop()
		else:
			stack.append(i)
	if len(stack) <= 2 and op == cl:
		print('Yes')
		return
	print('No')
solve()


from collections import Counter
n = int(input())
S = input()
D = Counter(S)
if ')' in D and '(' in D:
	if D['('] == D[')']:
		c = 0
		x = float('inf')
		y = float('-inf')
		for _ in S:
			if _ == '(':
				c += 1
			else:
				c -= 1
			x = min(x, c)
			y = max(x, c)
		if abs(x) < 2 and abs(y) < 2:
			print('Yes')
		else:
			print('No')
	else:
		print('No')
else:
	print('No')


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	print('No')
	exit(0)
d = 0
for c in s:
	if c == '(':
		d += 1
	else:
		d -= 1
	if d <= -2:
		print('No')
		exit(0)
print('Yes')


n = int(input())
s = input()
lc = 0
rc = 0
l = 0
r = 0
ch = 1
for i in range(len(s)):
	if s[i] == ')':
		l += 1
		lc += 1
	else:
		r += 1
		rc += 1
	if l - r >= 2:
		ch = 0
if ch == 1 and lc == rc:
	print('Yes')
else:
	print('No')


n = int(input())
a = list(input())
temp = []
for i in range(n):
	if i == 0:
		temp.append(a[i])
	elif len(temp) == 0:
		temp.append(a[i])
	elif a[i] == ')':
		if temp[-1] == '(':
			temp.pop()
		else:
			temp.append(a[i])
	else:
		temp.append(a[i])
if len(temp) == 2 and len(set(temp)) == 2 or len(temp) == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
z = 0
m = 0
for x in s:
	z += 2 * (x == '(') - 1
	m = min(m, z)
if z == 0 and m > -2:
	print('Yes')
else:
	print('No')


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
from collections import Counter
n = t()
a = list(ss())
if len(a) % 2 == 0:
	x = 0
	j = n - a[::-1].index('(') - 1
	flag = 0
	for i in range(n):
		if a[i] == '(':
			x += 1
		elif x > 0:
			x -= 1
		elif i < j and flag == 0:
			a.insert(i, '(')
			a.pop(j + 1)
			x += 1
			flag = 1
		else:
			x -= 1
			break
	if x == 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input(''))
s = str(input(''))
if n % 2 == 1:
	print('No')
	exit(0)
flag = False
stack = []
for c in s:
	if c == ')':
		if len(stack) == 0:
			if flag:
				print('No')
				exit(0)
			else:
				flag = True
		else:
			stack.pop()
	else:
		stack.append(c)
if len(stack) == 0 or (len(stack) == 1 and flag):
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
o = s.count('(')
c = s.count(')')
count = 0
pairs = 0
for b in s:
	if b == '(':
		count += 1
	elif count:
		count -= 1
		pairs += 1
if n % 2 or o != c:
	print('No')
elif pairs >= -1 + n // 2:
	print('Yes')
else:
	print('No')


N = int(input())
s = input()
balance = 0
number = 1
for i in range(len(s)):
	if s[i] == '(':
		balance += 1
	else:
		balance -= 1
	if balance == -1 and number > 0:
		d = s[i]
		balance += 1
		number -= 1
	if balance == -1 and number == 0:
		break
if number == 0:
	balance -= 1
if balance == 0:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
from math import ceil
n = int(input())
l = input().strip()
left = 0
right = 0
state = 0
for x in l:
	if x == '(':
		left += 1
		state += 1
	else:
		right += 1
		state -= 1
	if state <= -2:
		print('No')
		exit(0)
if left == right:
	print('Yes')
else:
	print('No')


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
s = input()
z = deque([])
for i in s:
	if i == '(':
		z.append(i)
	elif i == ')':
		if z:
			if z[-1] == '(':
				z.pop()
			else:
				print('No')
				exit()
		else:
			z.append(i)
if len(z) == 0 or list(z) == [')', '(']:
	print('Yes')
else:
	print('No')


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
s = input()
stack = []
for i in s:
	if i == '(':
		stack.append('(')
	elif i == ')':
		if len(stack) > 0 and '(' == stack[len(stack) - 1]:
			stack.pop()
		else:
			stack.append(')')
if stack == [')', '('] or stack == []:
	print('Yes')
else:
	print('No')


def check(s, n):
	c = 0
	for i in s:
		if i == '(':
			c += 1
		else:
			c -= 1
		if c < -1:
			break
	print('No' if c else 'Yes')
n = int(input())
s = input()
check(s, n)


import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline().strip()
c1 = 0
c2 = 0
for i in range(n):
	if s[i] == '(':
		c1 += 1
	else:
		c2 += 1
if c1 == c2:
	op = 0
	for i in range(n):
		if op < -1:
			break
		if s[i] == '(':
			op += 1
		else:
			op -= 1
	if op > 0 or op < 0:
		print('No')
	else:
		print('Yes')
else:
	print('No')


def process():
	n = int(input())
	s = input()
	if n % 2 == 1:
		print('No')
		return
	cnt = 0
	min_cnt = 1000000000000
	for i in range(n):
		if s[i] == '(':
			cnt += 1
		else:
			cnt -= 1
		min_cnt = min(cnt, min_cnt)
	if cnt != 0:
		print('No')
		return
	print(min_cnt >= -1 and 'Yes' or 'No')
process()


n = int(input())
cadena = input()
suma = 0
cambio = 0
todoBien = True
pila = []
for i in cadena:
	if i == '(':
		pila.append(i)
	elif len(pila) != 0 and pila[len(pila) - 1] == '(':
		pila.pop()
	elif cambio == 0:
		cambio += 1
	else:
		todoBien = False
if len(pila) > 1 or n % 2 != 0:
	todoBien = False
if todoBien == True:
	print('YES')
else:
	print('NO')


def unbalBracs(s):
	stk = []
	ubal = 0
	for b in s:
		if b == '(':
			stk.append(b)
		elif not stk or stk[-1] != '(':
			ubal += 1
		else:
			stk.pop()
	if len(stk) > 1:
		return 2
	return ubal
n = int(input())
s = input()
if n % 2 == 0:
	if unbalBracs(s) > 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


n = int(input())
s = input()
ans = 0
p = 0
a = 0
if n % 2 != 0:
	print('No')
	exit()
for i in s:
	if i == ')':
		if p > 0:
			p -= 1
		else:
			a += 1
	else:
		p += 1
if p == a and p < 2:
	print('Yes')
else:
	print('No')


n = int(input())
a = input()
(b, c) = ([], [])
for i in a:
	if i == '(':
		b.append('(')
	if i == ')':
		if b != []:
			b.pop()
		else:
			c.append(')')
if b == []:
	if c != []:
		print('NO')
	else:
		print('YES')
if b != []:
	if c == []:
		print('NO')
	elif b == ['('] and c == [')']:
		print('YES')
	else:
		print('NO')


n = int(input())
l1 = input()
k = 0
ans = ''
for i in l1:
	if i == '(':
		k += 1
	else:
		k -= 1
	if k == -2:
		ans = 'No'
		break
if k == 0:
	ans = 'Yes'
else:
	ans = 'No'
print(ans)


def solve(s, n):
	if len(s) % 2:
		return 'NO'
	stack = []
	open = s.count('(')
	close = s.count(')')
	if open != close:
		return 'NO'
	(o, c) = (0, 0)
	for i in s:
		if i == '(':
			o += 1
		else:
			c += 1
		if c - o > 1:
			return 'NO'
	return 'YES'
n = int(input())
s = input()
print(solve(s, n))


n = int(input())
string = input()
c = 0
flag = False
if n % 2 != 0:
	print('No')
else:
	fake_string = '(' + string + ')'
	temp = []
	for i in range(len(fake_string)):
		if fake_string[i] == '(':
			c += 1
		elif c != 0:
			c -= 1
		else:
			print('No')
			flag = True
			break
	if not flag:
		if c == 0:
			print('Yes')
		else:
			print('No')


n = int(input())
ss = input()
if ss.count('(') is not ss.count(')'):
	print('NO')
else:
	ans = []
	stack = []
	for i in ss:
		if i == '(':
			stack.append('(')
		elif stack == []:
			ans.append(')')
		else:
			stack.pop()
	if stack == []:
		print('YES')
	elif len(stack) == 1 and len(ans) == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
s = list(input())
stack = [0]
for item in s:
	if item == '(':
		stack.append(stack[-1] + 1)
	else:
		stack.append(stack[-1] - 1)
	if stack[-1] < -1:
		print('NO')
		break
else:
	if stack[-1] == 0:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase

def solution(seq, n):
	if n & 1 == 1:
		write('NO')
		return
	if seq.count('(') != seq.count(')'):
		write('NO')
		return
	balance = 0
	for c in seq:
		if c == '(':
			balance += 1
		else:
			balance -= 1
		if balance < -1:
			write('NO')
			return
	write('YES')

def main():
	n = r_int()
	seq = input()
	solution(seq, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


def solve(s):
	opn = 0
	for i in s:
		if i == '(':
			opn += 1
		else:
			opn -= 1
		if opn < -1:
			return 'NO'
	if opn != 0:
		return 'NO'
	return 'YES'
n = int(input())
s = input()
print(solve(s))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(stdin.readline().strip('\n'))
	st = []
	for i in range(n):
		if len(st) == 0:
			st.append(a[i])
		elif st[-1] == '(' and a[i] == ')':
			st.pop(-1)
		else:
			st.append(a[i])
	if len(st) == 0 or ((st[0] == ')' and st[-1] == '(') and len(st) == 2):
		print('Yes')
	else:
		print('No')


def check(str):
	stack = []
	for ch in str:
		if ch == '(':
			stack.append(ch)
		elif len(stack) > 0 and stack[-1] == '(':
			stack.pop(-1)
		else:
			stack.append(ch)
	if sorted(stack) == sorted(['(', ')']) or stack == []:
		return 'Yes'
	else:
		return 'No'
input()
print(check(input()))


import sys
n = int(input())
k = input()
l = [k[i] for i in range(n)]
char = [-1 if l[i] == ')' else 1 for i in range(n)]
su = [0] * n
su[0] = char[0]
for i in range(1, n):
	su[i] = su[i - 1] + char[i]
if su[-1] != 0:
	print('No')
else:
	for i in range(n):
		j = n - i - 1
		if l[j] == '(':
			l.pop(j)
			l = ['()'] + l
			break
	char = [-1 if l[i] == ')' else 1 for i in range(n)]
	su = [0] * n
	su[0] = char[0]
	for i in range(1, n):
		su[i] = su[i - 1] + char[i]
	for i in su:
		if i < 0:
			print('No')
			sys.exit(0)
	print('Yes')


N = int(input())
S = input()
cnt = 0
min_cnt = 0
for i in range(N):
	if S[i] == '(':
		cnt += 1
	else:
		cnt -= 1
		min_cnt = min(min_cnt, cnt)
if cnt == 0 and min_cnt >= -1:
	print('Yes')
else:
	print('No')


n = int(input())
s = str(input())
if n % 2 != 0:
	print('NO')
else:
	l = list(s)
	i = 0
	l1 = []
	while i < len(l):
		if i > 0 and l[i] == ')' and (len(l1) > 0) and (l1[-1] == '('):
			del l1[-1]
			i += 1
		else:
			l1.append(l[i])
			i += 1
	if len(l1) > 2 or len(l1) == 1:
		print('NO')
	elif len(l1) == 0:
		print('YES')
	elif l1[0] == ')' and l1[1] == '(':
		print('YES')
	else:
		print('NO')


n = int(input())
s = str(input())
co = 0
c1 = 0
for i in range(n):
	if s[i] == '(':
		co += 1
	else:
		co -= 1
	c1 = min(co, c1)
if c1 >= -1 and co == 0:
	print('Yes')
else:
	print('NO')


n = int(input())
s = str(input())
an = 0
g = []
vu = False
for i in range(n):
	if s[i] == '(':
		an += 1
	else:
		an -= 1
	if an == -1 and vu == False:
		an = 0
		vu = True
	else:
		g.append(an)
if vu:
	an -= 1
	g.append(an)
if -2 in g or -1 in g or an != 0:
	print('No')
	exit()
print('Yes')


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
n = int(input())
s = input()
if n % 2 == 1:
	print('No')
	exit()
baddies = []
offset = 0
for c in s:
	if len(baddies) == 0 and c == ')':
		offset -= 1
		continue
	if c == '(':
		baddies.append(1)
	else:
		baddies.pop()
if s[0] == ')' and len(s[1:]) > 1 and (len(set(s[1:])) == 1):
	print('No')
	exit()
if len(baddies) == 0 and offset == 0 or 1 + offset == 0:
	print('Yes')
else:
	print('No')


n = int(input())
a = input()
cnt1 = 0
cnt2 = 0
flag = 0
for i in range(n):
	if a[i] == '(':
		cnt1 += 1
	else:
		cnt2 += 1
if cnt1 != cnt2:
	print('No')
else:
	for i in range(n):
		if a[i] == '(':
			cnt1 += 1
		else:
			cnt2 += 1
		if cnt2 - cnt1 > 1:
			flag = 1
			break
	if flag:
		print('No')
	else:
		print('Yes')


n = int(input())
s = input()
L = []
for i in s:
	if i == '(':
		L.append(1)
	elif len(L) > 0 and L[-1] == 1:
		L.pop()
	else:
		L.append(-1)
if L == [] or L == [-1, 1]:
	print('Yes')
else:
	print('No')


n = int(input())
s = str(input())
c = 0
y = 0
l = list(s)
if len(l) % 2 != 0:
	print('NO')
else:
	for i in l:
		if i == ')':
			y = y - 1
			if y == -2:
				c = 1
				break
		elif i == '(':
			y = y + 1
	if c == 1 or y != 0:
		print('NO')
	else:
		print('YES')


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	print('No')
else:
	x = 0
	for i in s:
		if i == '(':
			x += 1
		else:
			x -= 1
		if x <= -2:
			print('No')
			break
	else:
		print('Yes')


n = int(input())
present = input().rstrip()
level = 0
min_level = 0
for ch in present:
	if ch == '(':
		level += 1
	else:
		level -= 1
		min_level = min(min_level, level)
if min_level >= -1 and level == 0:
	print('Yes')
else:
	print('No')


import sys
import collections
n = int(sys.stdin.readline().split()[0])
s = sys.stdin.readline().split()[0]
balance = 0
if n % 2 == 1:
	sys.stdout.write('No')
else:
	for i in range(n):
		if s[i] == '(':
			balance += 1
		else:
			balance -= 1
		if balance == -2:
			sys.stdout.write('No')
			break
	if balance > 0:
		sys.stdout.write('No')
	elif balance == 0:
		sys.stdout.write('Yes')


n = input()
s = input()
n = len(s)
if n % 2:
	print('No')
	exit()
if s.count('(') != n / 2:
	print('No')
	exit()
while s != s.replace('()', ''):
	for i in range(0, 15):
		s = s.replace(2 ** i * '(' + 2 ** i * ')', '')
if len(s) <= 2:
	print('Yes')
else:
	print('No')


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
arr = fast()
c = 0
ans = 0
if n % 2 == 1:
	print('No')
	exit()
for i in arr:
	if i == '(':
		ans += 1
		continue
	ans -= 1
	if ans < -1:
		print('No')
		exit()
if ans == 0:
	print('Yes')
else:
	print('No')


from collections import deque
de = deque([])
n = 0
bracket_list = []

def _input():
	global n, bracket_list
	n = int(input())
	temp = input()
	bracket_list = list(temp)
	return (n, bracket_list)

def _delete_correct_brackets():
	global de, n, bracket_list
	for x in bracket_list:
		if x == '(' or not de or de[-1] == ')':
			de.append(x)
		else:
			de.pop()
	if len(de) == 0:
		print('YES')
	elif len(de) == 2 and de[0] != de[1]:
		print('YES')
	else:
		print('NO')

def _processing():
	global n, bracket_list, de
	if n % 2 == 1:
		print('NO')
	else:
		_delete_correct_brackets()
(n, bracket_list) = _input()
_processing()


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
s = list(input())
l = []
if n % 2 or s.count(')') != s.count('('):
	print('NO')
	exit()
c = 0
k = 0
idx = -1
for i in range(n):
	if s[i] == '(':
		c += 1
	else:
		c -= 1
	if c == -1:
		idx = i
		break
if idx == -1:
	print('YES')
	exit()
s[idx] = ''
s.append(')')
s = ''.join(s)
ans = 'YES'
c = 0
for i in range(n):
	if s[i] == '(':
		c += 1
	else:
		c -= 1
	if c < 0:
		ans = 'NO'
print(ans)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
n = c.cin()
s = c.cin(str)
g = True
cou = 0
for el in s:
	if el == '(':
		cou += 1
	else:
		cou -= 1
	if cou == -1 and g == True:
		g = False
		cou = 0
	if cou == -1 and g == False:
		break
if cou == 0 and g:
	print('Yes')
elif cou == 1 and (not g):
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
stack = []
move = False
ans = True
for i in s:
	if i == '(':
		stack.append('(')
	elif i == ')':
		if len(stack):
			stack.pop()
		elif not move:
			move = True
		else:
			ans = False
			break
if len(stack) and move:
	stack.pop()
	move = False
print('Yes' if ans and (not len(stack)) and (not move) else 'No')


n = int(input())
s = input()
(a, b, c) = (0, 0, 0)
for c in s:
	if c == '(':
		a += 1
	elif a > 0:
		a -= 1
	else:
		b += 1
if a == 0 and b == 0:
	print('Yes')
elif a == 1 and b == 1:
	print('Yes')
else:
	print('No')


A = ['(', '(', ')']
n = int(input())
A = input()

def check_sequence(A):
	counter = 0
	for i in A:
		if i == '(':
			counter += 1
		else:
			counter -= 1
		if counter < -1:
			return 'No'
	if counter != 0:
		return 'No'
	return 'Yes'
print(check_sequence(A))


n = int(input())
a = list(input())
arr = []
for i in range(n):
	if len(arr) == 0:
		arr.append(a[i])
	else:
		x = arr.pop()
		if x == '(' and a[i] == ')':
			continue
		else:
			arr.append(x)
			arr.append(a[i])
if len(arr) == 0:
	print('Yes')
elif len(arr) == 2 and (arr[0] == '(' and arr[1] == ')' or (arr[0] == ')' and arr[1] == '(')):
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
ans = 'Yes'
x = 0
for i in s:
	if i == '(':
		x += 1
	elif i == ')':
		x -= 1
	if x < -1:
		ans = 'No'
		break
if x != 0:
	ans = 'NO'
print(ans)


n = int(input())
if n % 2 == 1:
	print('No')
	exit()
brackets = str(input())
stack = list()
k = 0
closed = 0
opened = 0
for br in brackets:
	if br == '(':
		stack.append(br)
		k += 1
		opened += 1
	else:
		if len(stack):
			stack.pop()
			k -= 1
		closed += 1
if (k == 1 or k == 0) and closed == opened:
	print('Yes')
else:
	print('No')


n = int(input())
arr = list(str(input()))
count = 0
if arr.count('(') != arr.count(')'):
	print('No')
else:
	for i in range(n):
		if arr[i] == '(':
			count += 1
		elif arr[i] == ')':
			count -= 1
		if count == -2:
			print('No')
			break
	else:
		print('Yes')


n = int(input())
s = input().rstrip()
l = []
x = list(s)
A = 0
if n % 2 != 0:
	print('No')
else:
	S = 0
	G = 0
	for i in range(0, len(x)):
		if A >= 2:
			G = -1
			break
		if x[i] == '(':
			l.append(x[i])
		elif x[i] == ')':
			if len(l) != 0:
				del l[0]
			else:
				A += 1
	if G == -1:
		print('No')
	elif A == len(l):
		print('Yes')
	else:
		print('No')


n = int(input())
start = 0
tmp = 0
wrong = 0
for b in input():
	if b == '(':
		start += 1
	elif start > 0:
		start -= 1
	else:
		wrong += 1
if wrong == 1:
	if start == 1:
		print('Yes')
	else:
		print('No')
elif wrong == 0:
	if start == 0:
		print('Yes')
	else:
		print('No')
else:
	print('No')


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
else:
	dp = [0] * (n + 1)
	flag = 0
	for i in range(1, n + 1):
		if s[i - 1] == '(':
			dp[i] = dp[i - 1] + 1
		else:
			dp[i] = dp[i - 1] - 1
		if dp[i] < -1:
			flag = 1
			print('No')
			break
	if flag == 0:
		if dp[n] != 0:
			print('No')
		else:
			print('Yes')


_ = input()

def parse(s):
	ret = []
	summ = 0
	last = s[0]
	for c in s:
		if last != c:
			last = c
			ret.append(summ)
			summ = 1 if c == '(' else -1
			continue
		if c == '(':
			summ += 1
		else:
			summ -= 1
	if summ != 0:
		ret.append(summ)
	return ret

def ok(arr):
	s = 0
	for i in arr:
		s += i
		if s < 0:
			return False
	return True

def almost_ok(arr):
	s = 0
	ret = False
	for i in arr:
		s += i
		if s == -1:
			if not ret:
				ret = True
		if s < -1:
			return False
	return ret
s = input()
if s.count('(') != s.count(')'):
	print('No')
	exit(0)
s = parse(s)
ao = almost_ok(s) or ok(s)
print('Yes' if ao else 'No')


input()
s = input()
ct1 = 0
ct2 = 0
for i in s:
	if i == '(':
		ct1 += 1
	else:
		ct1 -= 1
	ct2 = min(ct2, ct1)
if ct1 == 0 and ct2 >= -1:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
i = s.find(')')
if i == -1:
	print('No')
	exit()
s = s[:i] + s[i + 1:] + ')'
count = 0
for c in s:
	if c == '(':
		count += 1
	else:
		count -= 1
		if count < 0:
			print('No')
			exit()
if count == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()

def possible(n, s):
	lc = 0
	rc = 0
	for e in s:
		if e is '(':
			lc += 1
		else:
			rc += 1
		if rc - lc >= 2:
			return False
	return lc == rc
r = possible(n, s)
print('Yes' if r else 'No')


input()
s = input()
cnt = 0
ans = 'Yes'
for item in s:
	if item == '(':
		cnt += 1
	else:
		cnt -= 1
	if cnt <= -2:
		ans = 'No'
		break
if ans == 'Yes':
	if cnt:
		ans = 'No'
print(ans)


n = int(input())
seq = input()
l = seq.count('(')
r = seq.count(')')
count = 0
if l != r:
	print('No')
elif len(seq) == 0:
	print('Yes')
else:
	stack = []
	for i in seq:
		if i == '(':
			stack.append(i)
		elif len(stack) != 0:
			stack.pop()
		else:
			count += 1
	if count == 1 or count == 0:
		print('Yes')
	else:
		print('No')


n = int(input())
s = input()
ans = s.count('(') == s.count(')')
if ans:
	b = 0
	was = False
	for i in s:
		if i == '(':
			b += 1
		else:
			b -= 1
		if b == -1:
			if was:
				ans = False
				break
			was = True
			b = 0
print('Yes' if ans else 'No')


cts = [0, 0]
n = int(input())
seq = list(input())
tick = 0
tf = 0
mt = 0
for i in range(0, len(seq)):
	if seq[i] == '(':
		cts[0] += 1
		tick += 1
	else:
		cts[1] += 1
		tick -= 1
	mt = min(mt, tick)
if cts[0] == cts[1] and mt >= -1:
	print('Yes')
else:
	print('No')


n = int(input())
str = input()
cnt = 0
m = cnt
for i in range(len(str)):
	if str[i] == '(':
		cnt += 1
	else:
		cnt -= 1
		m = min(cnt, m)
if m >= -1 and cnt == 0:
	print('Yes')
else:
	print('No')


n = int(input())
bracket = input().strip()
if bracket.count('(') != bracket.count(')'):
	print('No')
else:
	(l_bracket, r_bracket) = (0, 0)
	temp = 1
	for i in bracket:
		if i == '(':
			l_bracket += 1
		if i == ')':
			r_bracket += 1
		if r_bracket - l_bracket > 1:
			temp = 0
			break
	if temp == 1:
		print('Yes')
	else:
		print('No')


n = int(input())
mn = 0
s = input()
balance = 0
for i in range(n):
	if s[i] == '(':
		balance += 1
	else:
		balance -= 1
	mn = min(mn, balance)
if balance == 0:
	if mn < -1:
		print('No')
	else:
		print('Yes')
else:
	print('No')


from sys import stdin
from collections import defaultdict, Counter
from bisect import bisect_left
from math import sqrt
from heapq import *

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = 1
while t:
	t -= 1
	n = iinput()
	s = input()
	l = s.count('(')
	if n & 1 or l != n // 2:
		print('No')
	else:
		stack = []
		ans = 0
		for e in s:
			if e == '(':
				stack.append(e)
			elif stack:
				stack.pop()
			else:
				ans += 1
		print('Yes' if ans <= 1 else 'No')


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	print('No')
else:
	m = 0
	for c in s:
		if c == '(':
			m += 1
		else:
			m -= 1
			if m < -1:
				print('No')
				break
	else:
		print('Yes')


import sys
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	n = int(input())
	if n != 0:
		s = input()
	flag = True
	(cnt, x, y) = (0, 0, 0)
	for i in range(n):
		if s[i] == ')':
			y += 1
			if y - x > cnt:
				cnt += 1
			if cnt > 1:
				flag = False
				break
		if s[i] == '(':
			x += 1
	if x != y:
		flag = False
	if n % 2 == 1:
		flag = False
	print('Yes' if flag else 'No')
main()


n = int(input())
st = input()
if n % 2 != 0:
	print('No')
else:
	a1 = a2 = 0
	flag = True
	for pt in st:
		if pt == ')':
			a1 += 1
		else:
			a2 += 1
		if a1 - a2 > 1:
			flag = False
			break
	if flag and abs(a2 - a1) == 0:
		print('Yes')
	else:
		print('No')


def solve(n, seq):
	incorrect = 0
	currentOpen = 0
	index = 0
	while index < n:
		if index == 0:
			if seq[index] == ')':
				incorrect += 1
			else:
				currentOpen += 1
		elif seq[index] == '(':
			currentOpen += 1
		elif currentOpen < 1:
			incorrect += 1
		else:
			currentOpen -= 1
		index += 1
	if incorrect <= 1 and incorrect == currentOpen:
		return 'Yes'
	else:
		return 'No'
n = int(input())
seq = list(input())
print(solve(n, seq))


def func(A):
	if len(A) % 2 != 0:
		print('No')
		return
	stack = []
	for i in A:
		if i == '(':
			stack.append(i)
		elif stack and stack[-1] == '(':
			stack.pop()
		else:
			stack.append(i)
	if len(stack) == 0:
		print('Yes')
		return
	if len(stack) == 2 and stack[0] == ')' and (stack[1] == '('):
		print('Yes')
		return
	print('No')
_ = input()
func(input())


n = int(input())
braces = input()
stack = []
flase_stack = []
count_1 = 0
count_2 = 0
flag = False
for i in braces:
	if i == '(':
		stack.append(i)
		count_1 += 1
	elif i == ')':
		count_2 += 1
		if stack.__len__() != 0:
			if stack[-1] == '(':
				stack.pop()
			else:
				stack.append(i)
		else:
			stack.append(i)
if (len(stack) == 0 or len(stack) == 2) and count_1 == count_2:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
(a, b) = (0, 0)
for x in s:
	if x == ')':
		if b > 0:
			b -= 1
		else:
			a += 1
	else:
		b += 1
if a == b == 0 or a == b == 1:
	print('Yes')
else:
	print('No')


t = int(input())
ss = input()
(op, out) = (0, 0)
for i in range(0, len(ss)):
	if ss[i] == '(':
		op += 1
	elif op > 0:
		op -= 1
	else:
		out += 1
if op == 0 and out == 0:
	print('Yes')
elif op == 1 and out == 1:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
a = []
c = 0
for i in s:
	if i == ')':
		if a and a[-1] == '(':
			v = a.pop()
			c -= 1
		else:
			a.append(i)
			c += 1
	else:
		a.append(i)
		c += 1
if c == 0:
	print('YES')
elif c == 2 and a[0] != a[1]:
	print('YES')
else:
	print('NO')


size = int(input())
sequence = input()
counter = 0
possible = True
for l in sequence:
	if l == ')':
		counter -= 1
	elif l == '(':
		counter += 1
	if counter < -1:
		possible = False
		break
if counter != 0:
	possible = False
if possible:
	print('Yes')
else:
	print('No')


n = int(input())
a = input()
s = 0
v = 0
f = False
for i in range(n):
	if a[i] == '(':
		s += 1
	if a[i] == ')':
		s -= 1
		if s < -1:
			v += 2
			break
if s != 0:
	print('No')
elif v > 1:
	print('No')
else:
	print('Yes')


n = int(input())
stck = []
temp = input()
lst = [a for a in temp]
stck.append(lst[0])
for i in range(1, n):
	temp = lst[i]
	if len(stck) != 0 and temp == ')' and (stck[-1] == '('):
		stck.pop()
	else:
		stck.append(temp)
res = 'No'
if len(stck) == 0:
	res = 'Yes'
elif len(stck) == 2:
	if stck[0] == ')' and stck[1] == '(':
		res = 'Yes'
print(res)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
n = ii()
s = input()
if n % 2:
	exit(print('No'))
o = c = 0
f = True
for i in s:
	if i == '(':
		o += 1
	elif i == ')' and c == o:
		if f:
			f = False
		else:
			break
	else:
		c += 1
if not f:
	c += 1
print('No') if o != c else print('Yes')


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
a = si()
if n % 2:
	print('NO')
	exit()
p = 0
for i in range(n):
	if p > 1:
		print('NO')
		exit()
	if a[i] == '(':
		p -= 1
	else:
		p += 1
print('No' if p else 'Yes')


n = int(input())
seq = list(input())
stack = 0
minstack = 0
for i in seq:
	if i == '(':
		stack += 1
	else:
		stack -= 1
	if stack < minstack:
		minstack = stack
if stack == 0 and minstack >= -1:
	print('Yes')
else:
	print('No')


def solvea():
	n = int(input())
	d = int(input())
	e = 5 * int(input())
	best = 0
	for enr in range(n // e + 1):
		curr = e * enr
		curr += d * ((n - curr) // d)
		if curr <= n and curr > best:
			best = curr
	print(n - best)

def solveb():
	a = int(input())
	b = int(input())
	n = int(input())
	ans = 0
	for i in range(a + 1):
		for j in range(b + 1):
			if i + j == n:
				ans += 1
	print(ans)

def solvec():
	n = int(input())
	curr_bal = 0
	min_bal = 0
	for e in input():
		if e == '(':
			curr_bal += 1
		else:
			curr_bal -= 1
		if curr_bal < min_bal:
			min_bal = curr_bal
	if min_bal >= -1 and curr_bal == 0:
		print('Yes')
	else:
		print('No')

def __starting_point():
	solvec()
__starting_point()


import sys
n = int(sys.stdin.readline())
string = sys.stdin.readline()
string = string.rstrip()
count = 0
flag = 0
for i in string:
	if i == '(':
		count += 1
	else:
		count -= 1
	if count <= -2:
		flag = 1
		break
if flag or count != 0:
	print('NO')
else:
	print('YES')


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()
	d = get_int()
	e = get_int()
	best = float('inf')
	while n >= 0:
		best = min(best, n % d)
		n -= 5 * e
	return best

def solve_b():
	b = get_int()
	g = get_int()
	n = get_int()
	return min(b, n) - max(0, n - g) + 1

def solve_c():
	n = get_int()
	s = get_str()
	open = 0
	for (idx, char) in enumerate(s):
		if char == '(':
			open += 1
		else:
			open -= 1
		if open < -1:
			return False
	return open == 0
print(yes_no(solve_c()).title())


n = int(input())
s = input()
d = {'(': 0, ')': 0}
maxm = 0
for i in range(n):
	if s[i] == '(':
		d['('] += 1
	else:
		d[')'] += 1
	maxm = max(maxm, d[')'] - d['('])
if d['('] != d[')'] or maxm > 1:
	print('No')
else:
	print('Yes')


N = int(input())
s = input()
suma = 0
maz = 0
for i in s:
	suma += 1 if i == '(' else -1
	maz = min(maz, suma)
print('Yes' if maz >= -1 and suma == 0 else 'No')


n = int(input())
s = input()
mn = 0
balance = 0
for i in s:
	if i == '(':
		balance += 1
	else:
		balance -= 1
	mn = min(mn, balance)
if balance != 0 or mn < -1:
	print('NO')
else:
	print('YES')


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = inp(1)
s = input().strip()
stack = []
for c in s:
	if len(stack) != 0 and c == ')':
		if stack[-1] == ')':
			stack.append(c)
		else:
			stack.pop(-1)
	else:
		stack.append(c)
stack.sort()
if len(stack) == 0 or stack == ['(', ')']:
	print('Yes')
else:
	print('No')


n = int(input())
seq = input()
counter = 0
for c in seq:
	if c == '(':
		counter += 1
	else:
		counter -= 1
	if counter < -1:
		break
if counter == 0:
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
if n % 2:
	print('No')
else:
	fault = 0
	score = 0
	for i in s:
		if i == '(':
			score += 1
		elif score > 0:
			score -= 1
		else:
			fault += 1
			if fault > 1:
				print('No')
				break
	if fault < 2:
		if score != fault:
			print('No')
		else:
			print('Yes')


n = int(input())
s = input()
diff = 0
min_diff = 0
for i in range(n):
	if s[i] == '(':
		diff += 1
	else:
		diff -= 1
		min_diff = min([min_diff, diff])
if min_diff >= -1 and diff == 0:
	print('Yes')
else:
	print('No')


cnt = 0
n = int(input())
s = input()
f = 0
for i in s:
	if i == '(':
		cnt += 1
	else:
		cnt -= 1
	if cnt == -2:
		f = 1
		break
if f == 0 and cnt == 0:
	print('Yes')
else:
	print('No')


n = int(input())
string_val = input()
flag = 0
arr = []
for x in string_val:
	if x == '(':
		arr.append(1)
	else:
		arr.append(-1)
if sum(arr) != 0:
	flag = 0
else:
	sum = 0
	for y in arr:
		if sum == -2:
			flag = 0
			break
		else:
			flag = 1
			sum = sum + y
if flag == 1:
	print('Yes')
else:
	print('No')


def checker(n, string):
	count = 0
	for i in string:
		if i == ')':
			count -= 1
		else:
			count += 1
	if count == 0:
		return True
	else:
		return False

def solver(n, string):
	if n % 2 != 0:
		return 'No'
	elif n != len(string):
		return 'No'
	else:
		count = 0
		for i in string:
			if i == ')':
				count -= 1
			else:
				count += 1
			if count < -1:
				return 'No'
	return 'Yes'
n = int(input())
string = input()
if checker(n, string):
	print(solver(n, string))
else:
	print('No')


def solve(sequence):
	balance = 0
	for p in sequence:
		if p == '(':
			balance += 1
		else:
			balance -= 1
		if balance < -1:
			return False
	return balance == 0
n = int(input())
s = input()
(left, right) = (0, 0)
print('Yes' if solve(s) else 'No')


import math

class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	s = input()
	l = []
	for i in s:
		if len(l) and l[-1] == '(' and (i == ')'):
			del l[-1]
		else:
			l.append(i)
	print('YES' if len(l) == 0 or (len(l) == 2 and ')' in l and ('(' in l)) else 'NO')
query_count = 1
for j in range(query_count):
	solve()


n = int(input())
s = input()
if s.count('(') != s.count(')'):
	exit(print('No'))
st = []
ct = 0
for i in range(n):
	if s[i] == '(':
		st.append(s[i])
	if s[i] == ')':
		if len(st) != 0:
			st.pop()
		else:
			ct += 1
if ct > 1:
	print('No')
else:
	print('Yes')


stack = []
input()
seq = input()
for br in seq:
	if br == '(':
		stack.append(br)
	elif br == ')':
		if stack and stack[-1] == '(':
			stack.pop()
		else:
			stack.append(br)
if not stack:
	print('Yes')
elif len(stack) == 2 and '(' in stack and (')' in stack):
	print('Yes')
else:
	print('No')


n = int(input())
s = input()
lst = []
ans = []
if n % 2 != 0:
	print('no')
else:
	for i in s:
		if i == '(':
			lst.append(i)
		else:
			f = 0
			if len(lst) > 0 and lst[-1] == '(':
				lst.pop()
				f = 1
			if f == 0:
				ans.append(i)
	if (len(lst) == 0 or len(lst) == 1) and (len(ans) == 0 or len(ans) == 1):
		print('yes')
	else:
		print('no')


n = int(input())
expr = input()
first = expr.count('(')
if first == n - first:
	stack = []
	stack2 = []
	for val in expr:
		if val == '(':
			stack.append('(')
		elif stack:
			stack.pop(0)
		else:
			stack2.append(')')
	if len(stack) < 2 and len(stack2) < 2:
		print('Yes')
	else:
		print('No')
else:
	print('No')


n = int(input())
s = input()
c = 0
ck = 1
for i in s:
	if i == '(':
		c += 1
	else:
		c -= 1
	if c < -1:
		ck = 0
		break
if ck == 0:
	print('No')
elif c == 0:
	print('Yes')
else:
	print('No')


def main():
	n = int(input())
	s = input()
	left = 0
	right = 0
	for i in s:
		if i == '(':
			left += 1
		elif left > 0:
			left -= 1
		else:
			right += 1
	if left == right and left <= 1:
		print('Yes')
		return
	print('No')
main()


from sys import exit
n = int(input())
s = input()
cur = 0
for ch in s:
	if ch == '(':
		cur += 1
	else:
		cur -= 1
	if cur == -2:
		print('No')
		exit(0)
print('Yes' if cur == 0 else 'No')


n = int(input())
s = input()
y = n % 2
if y:
	print('NO')
	exit()
l = []
count = 1
for i in range(n):
	if s[i] == '(':
		l.append(s[i])
	if s[i] == ')':
		if len(l) == 0:
			count -= 1
		else:
			x = l.pop()
if len(l) > 1 or count < 0:
	print('NO')
else:
	print('YES')


n = int(input())
seq = input()
(cnt1, cnt2) = (0, 0)
for i in seq:
	if i == '(':
		cnt1 += 1
	else:
		cnt1 -= 1
	cnt2 = min(cnt1, cnt2)
if cnt1 == 0 and cnt2 >= -1:
	print('Yes')
else:
	print('No')


n = int(input())
x = input()
c = 0
cmin = 0
for i in range(n):
	if x[i] == '(':
		c += 1
	else:
		c -= 1
	if c == -2:
		cmin += 1
if c != 0 or cmin > 0:
	print('No')
else:
	print('Yes')


a = int(input())
(_0, _1) = (0, 0)
for i in input():
	if i == '(':
		_0 += 1
	elif _0:
		_0 -= 1
	else:
		_1 += 1
if _1 == _0 == 1 or _1 == _0 == 0:
	print('Yes')
else:
	print('No')


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
stack = [1]
_ = ii()
for i in input():
	if i == '(':
		stack.append(1)
	else:
		if not stack:
			print('No')
			exit()
		stack.pop()
print('No' if len(stack) != 1 else 'Yes')


n = int(input())
s = input()
(cnt, flag) = (0, 0)
for i in s:
	if i == '(':
		cnt += 1
	elif i == ')':
		cnt -= 1
	if cnt < -1:
		flag = 1
if cnt != 0 or flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
s = input()
l = list()
open_ = 0
close_ = 0
pair = 0
for i in s:
	if i == '(':
		open_ += 1
		l.append(i)
	else:
		close_ += 1
		if len(l) > 0:
			l.pop()
			pair += 1
if open_ == close_ and (open_ - 1 == pair or open_ == pair):
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
if n % 2 == 1:
	print('NO')
else:
	k = 0
	f = False
	for i in range(n):
		k = k - 1 if s[i] == ')' else k + 1
		if k <= -2:
			f = True
			break
	if k > 1:
		f = True
	if f:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
n = int(stdin.readline().strip())
s = stdin.readline().strip()
ctr = 0
flag = False
for i in s:
	if i == '(':
		ctr += 1
	else:
		ctr -= 1
		if ctr < -1:
			flag = True
			break
if ctr != 0 or flag:
	stdout.write('No')
else:
	stdout.write('Yes')


n = int(input())
s = input()
if n % 2 == 1:
	print('No')
	exit()
op = 0
cl = 0
for i in s:
	if i == '(':
		op += 1
	elif op > 0:
		op -= 1
	elif cl < 1:
		cl += 1
	else:
		print('No')
		exit()
op -= cl
print('Yes' if op == 0 else 'No')


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
s = ins()
if n % 2 != 0:
	print('No')
else:
	count = 0
	ans = True
	for i in s:
		count += 1 if i == '(' else -1
		if count <= -2:
			ans = False
			break
	if count != 0:
		ans = False
	print('Yes' if ans else 'No')


(a, b, c) = (input(), 0, 0)
a = input()
for x in a:
	if x == '(':
		b += 1
	else:
		b -= 1
		c = min(c, b)
if b == 0 and c >= -1:
	print('Yes')
else:
	print('No')


import sys
n = int(input())
b = list(sys.stdin.readline().rstrip())
stk = list()
target = -1
for i in range(n):
	if b[i] == '(':
		stk.append('(')
	else:
		if len(stk) == 0:
			target = i
			break
		stk.pop()
if target == -1 and len(stk) != 0:
	print('No')
	exit(0)
if target == -1:
	print('Yes')
	exit(0)
ch = b[target]
del b[target]
b1 = [ch] + b
b2 = b + [ch]
stk.clear()
target = -1
for i in range(n):
	if b1[i] == '(':
		stk.append('(')
	else:
		if len(stk) == 0:
			target = i
			break
		stk.pop()
if len(stk) == 0 and target == -1:
	print('Yes')
	exit(0)
stk.clear()
target = -1
for i in range(n):
	if b2[i] == '(':
		stk.append('(')
	else:
		if len(stk) == 0:
			target = i
			break
		stk.pop()
if len(stk) == 0 and target == -1:
	print('Yes')
	exit(0)
print('No')


n = int(input())
b = input()
stack = []
c1 = 0
c2 = 0
for c in b:
	if c == '(':
		c1 += 1
	else:
		c2 += 1
for c in b:
	if c == '(':
		stack.append(c)
	if c == ')':
		if stack:
			stack.pop()
if n % 2 == 0:
	if c1 != c2:
		print('No')
	elif len(stack) > 1:
		print('No')
	else:
		print('Yes')
else:
	print('No')