Example

Input

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


Output

Yes
#include <iostream>
#include <vector>
#include <climits>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) cin >> s[i];

	vector<pair<int, int>> v(n, { 0, 0 });
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int tmp = 0;
		for (int j = 0; j < s[i].size(); ++j) {
			if (s[i][j] == '(') tmp++;
			else tmp--;
			v[i].second = min(v[i].second, tmp);
		}
		v[i].first = tmp;
		sum += tmp;
	}

	if (sum != 0) {
		cout << "No" << endl;
		return 0;
	}

	vector<pair<int, int>> v1, v2, v3;
	for (int i = 0; i < n; ++i) {
		if (v[i].second >= 0) v1.push_back(v[i]);
		else if (v[i].first >= 0) v2.push_back(v[i]);
		else v3.push_back(v[i]);
	}

	int now = 0;
	for (auto i : v1) {
		now += i.first;
	}
	
	vector<bool> used(n, false);
	bool update = true;
	while (update) {
		update = false;
		for (int i = 0; i < v2.size(); ++i) {
			if (used[i]) continue;
			if (-v2[i].second <= now) {
				now += v2[i].first;
				used[i] = true;
				update = true;
			}
		}
	}
	// cout << now << " " << v2.size() << endl;

	for (int i = 0; i < v2.size(); ++i) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	vector<vector<int>> x;
	for (auto i : v3) x.push_back({ i.first - i.second, i.first, i.second });
	sort(x.begin(), x.end());
	reverse(x.begin(), x.end());

	for (auto i : x) {
		// cout << now << " " << i[2] << endl;
		if (-i[2] > now) {
			cout << "No" << endl;
			return 0;
		}
		now += i[1];
	}

	cout << "Yes" << endl;

	return 0;
}
