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: Wrong Answer)

// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(ll (i)=(m);(i)<(n);(i)++)
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
string ds(string s)
{
	stack<char> st;
	for ( auto e : s)
	{
		if (st.empty())
			st.push(e);
		else if (st.top() == '(' && e == ')')
			st.pop();
		else
			st.push(e);
	}
	string res;
	for (int i = 0; !st.empty(); i++)
	{
		res += st.top();
		st.pop();
	}
	reverse(res.begin(), res.end());
	return res;
}
void solve()
{
	ll n;
	cin >> n;
	std::vector<string> col;
	rep(i, n)
	{
		string x;
		cin >> x;
		string y = ds(x);
		if (!y.empty())
			col.pb(y);
	}
	int l = 0, r = 0;
	// std::vector<string> lat;
	std::vector<pair<int, int>> val;
	for (auto e : col)
	{
		if (e.front() == e.back())
		{
			if (e.front() == '(')
				l += e.size();
			else
				r += e.size();
		}
		else
		{
			int x = 0;
			for (auto E : e)
			{
				x++;
				if (E == '(')
					break;
			}
			val.pb({x, e.size() - x});
		}
	}


	bool ans = true;
	for (auto e : val)
	{


		l -= e.first;
		r -= e.second;
		if (l < 0 || r < 0)
		{
			ans = false;
			break;
		}
	}
	if (l != r)
		ans = false;
	cout << (ans ? "Yes" : "No");
	cout << endl;



}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	//cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}