Example

Input

3
()(()((
))()()(()
)())(())


Output

Yes
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	using P = pair<int,int>;
	int n;
	cin >> n;
	vector<P> vecUp,vecDown;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		int cnt = 0,mi = 0;
		for(int j = 0;j < s.length();j++){
			if(s[j] == '(') cnt++;
			else cnt--;
			mi = min(mi,cnt);
		}
		if(cnt >= 0) vecUp.emplace_back(-mi,cnt - mi);
		else vecDown.emplace_back(-mi,cnt - mi);
	}
	sort(vecUp.begin(),vecUp.end());
	sort(vecDown.begin(),vecDown.end(),[](const P &p1,const P &p2){
		return p1.second > p2.second;
	});
	int cnt = 0,mi = 0;
	for(P p : vecUp){
		cnt -= p.first;
		mi = min(mi,cnt);
		cnt += p.second;
	}
	for(P p : vecDown){
		cnt -= p.first;
		mi = min(mi,cnt);
		cnt += p.second;
	}
	if(cnt || mi < 0) cout << "No" << endl;
	else cout << "Yes" << endl;
}
