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 C++ (GCC 9.2.1) (judge verdict: Accepted)

// https://atcoder.jp/contests/abc167/tasks/abc167_f
// 初期文字列から()をすべて削除し、すべて))))(((という文字列にする
// )の数でソート 同じ場合は(が多い順
// )が少ない順につなげて()を消してく
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000005

// bool comp(const P& p1,const P& p2){
// 	if(p1.first == p2.first){
// 		return p1.second > p2.second;
// 	}
// 	return p1.first < p2.first;
// }

int main() {
	int n;
	vector<P> vecl;
	vector<P> vecr;
	cin >> n;
	int eq_max = 0;

	string s;
	rep(i,n){
		int rn=0,ln=0;
		cin >> s;
		rep(j,s.size()){
			if(s[j]==')'){
				if(ln>0) ln--;
				else rn++;
			}else{
				ln++;
			}
		}
		if(rn == 0 && ln == 0)continue;
		else if(ln>rn) vecl.push_back(P(rn,ln));
		else if(ln == rn) eq_max = max(eq_max,ln);
		else vecr.push_back(P(ln,rn));
	}
	// sort(all(vecl),comp);
	sort(all(vecl));
	// rep(i,vec.size()){outsp(vec[i].first);outl(vec[i].second);}
	int rcum=0;
	rep(i,vecl.size()){
		rcum -= vecl[i].first;
		if(rcum<0){
			outl("No");
			return 0;
		}
		rcum += vecl[i].second;
	}

	sort(all(vecr));
	// rep(i,vec.size()){outsp(vec[i].first);outl(vec[i].second);}
	int lcum=0;
	rep(i,vecr.size()){
		lcum -= vecr[i].first;
		if(lcum<0){
			outl("No");
			return 0;
		}
		lcum += vecr[i].second;
	}



	if(rcum>=eq_max && rcum==lcum){
		outl("Yes");
	}else{
		outl("No");
	}

    return 0;
}