Example

Input

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


Output

Yes
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
string str[100];
bool used[100];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> str[i];
	}
	vector<P> v;
	for (int i = 0; i < N; i++) {
		int s = 0;
		int m = 0;
		for (int j = 0; j < str[i].size(); j++) {
			if (str[i][j] == '(') s++;
			else s--;
			m = min(s, m);
		}
		if (s >= 0) v.emplace_back(s, m);
	}
	int l = 0;
	while (1) {
		bool update = 0;
		for (int i = 0; i < v.size(); i++) {
			if (used[i] || l < -v[i].second) continue;
			l += v[i].first;
			used[i] = 1;
			update = 1;
		}
		if (!update) break;
	}
	for (int i = 0; i < v.size(); i++) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	v.clear();
	for (int i = 0; i < N; i++) {
		int s = 0;
		int m = 0;
		for (int j = str[i].size() - 1; j >= 0; j--) {
			if (str[i][j] == ')') s++;
			else s--;
			m = min(s, m);
		}
		if (s >= 0) v.emplace_back(s, m);
	}
	memset(used, 0, sizeof(used));
	int r = 0;
	while (1) {
		bool update = 0;
		for (int i = 0; i < v.size(); i++) {
			if (used[i] || r < -v[i].second) continue;
			r += v[i].first;
			used[i] = 1;
			update = 1;
		}
		if (!update) break;
	}
	for (int i = 0; i < v.size(); i++) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (l == r) cout << "Yes" << endl;
	else cout << "No" << endl;
}
