Problem:
Score : 600 points

Problem Statement

A bracket sequence is a string that is one of the following:

An empty string;

The concatenation of (, A, and ) in this order, for some bracket sequence A ;

The concatenation of A and B in this order, for some non-empty bracket sequences A and B /

Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?

Constraints

1 \leq N \leq 10^6

The total length of the strings S_i is at most 10^6.

S_i is a non-empty string consisting of ( and ).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.

Sample Input 1

2
)
(()

Sample Output 1

Yes

Concatenating (() and ) in this order forms a bracket sequence.

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

4
((()))
((((((
))))))
()()()

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No

Solution in Julia (1.4.0) (judge verdict: Wrong Answer)

parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function eval(a::Tuple{Int,Int},b::Tuple{Int,Int})
	if a[1]-a[2]>b[1]-b[2]
		1
	elseif a[1]-a[2]==b[1]-b[2]
		0
	else
		-1
	end
end

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = l>>1
		while eval(x,h[k])==1&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if eval(z,h[2*k])>=0
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if eval(z,h[2*k])>=0&&eval(z,h[2*k+1])>=0
					break
				else
					t = eval(h[2*k],h[2*k+1])>=0 ? 2*k : 2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
	n = readline() |> parseInt
	a = Tuple{Int,Int}[]
	b = Tuple{Int,Int}[]
	f = 0
	lx = 0
	rx = 0
	for i in 1:n
		s = readline() |> chomp
		l = 0
		r = 0
		for j in 1:length(s)
			if s[j]=='('
				l += 1
			else
				if l==0
					r+=1
				else
					l-=1
				end
			end
		end
		if l>r
			push!(a,(l,r))
		else
			push!(b,(l,r))
		end
		lx+=l
		rx+=r
	end
	f = 0
	if lx!=rx
		f = 1
	end
	lc = 0
	a = sort(a,by=x->(x[2],x[2]-x[1]))
	for i in 1:length(a)
		if lc-a[i][2]<0
			f = 1
		end
		lc+=a[i][1]-a[i][2]
	end
	b = sort(b,by=x->x[2],rev=true)
	for i in 1:length(b)
		if lc-b[i][2]<0
			f = 1
		end
		lc += b[i][1]-b[i][2]
	end
	println(f==0 ? "Yes" : "No")
end

main()