Example

Input

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


Output

Yes
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
int main()
{
	cin>>N;
	vector<pair<int,int> >A(N);
	for(int i=0;i<N;i++)
	{
		string s;cin>>s;
		int c=0,m=0;
		for(char x:s)
		{
			if(x==')')c--;
			else c++;
			if(m>c)m=c;
		}
		A[i]=make_pair(c,m);
	}
	sort(A.begin(),A.end(),[](pair<int,int>a,pair<int,int>b)
	{
		if(a.first>=0)
		{
			if(b.first>=0)
			{
				return a.second>b.second;
			}
			else return true;
		}
		else
		{
			if(b.first>=0)
			{
				return false;
			}
			else
			{
				return a.first-a.second>b.first-b.second;
			}
		}
	});
	int C=0;
	for(pair<int,int>p:A)
	{
		if(C+p.second<0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		C+=p.first;
	}
	cout<<(C?"No":"Yes")<<endl;
}

