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[2]<b[2]||(a[2]==b[2]&&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}[(0,0) for i in 1:n]
	f = 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
		a[i]=(l,r)
	end
	ls = 0
	rs = 0
	for i in 1:n
		ls+=a[i][1]
		rs+=a[i][2]
	end
	if ls!=rs
		println("No")
	else
		a = sort(a,by=x->(x[2],x[1]))
		h = Tuple{Int,Int}[]
		f = 0
		lc = 0
		for i in n:-1:1
			if a[i][2]==0&&a[i][1]>0
				f = i
				lc+=a[i][1]
				break
			end
		end
		if f == 0
			println("No")
		else
			for i in 1:n
				if a[i]!=f
					hpush(h,a[i])
				end
			end
			for i in 1:n-1
				b = hpop(h)
				lc-=a[i][2]
				if lc<0
					f=0
				end
				lc+=a[i][1]
			end
			if f==0
				println("No")
			else
				println("Yes")
			end
		end
	end
end

main()