Example

Input

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


Output

Yes
#include <bits/stdc++.h>

using namespace std;

const int N=110;
const int inf=1e6+100;
int vis[N];
char s[N];
struct node
{
    int cnt,low,high;
}S[N];
bool cmp(node n1,node n2)
{
    return n1.cnt>n2.cnt;
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        int len=strlen(s);
        S[i].low=inf;
        for(int j=0;j<len;j++)
        {
            if(s[j]=='(') S[i].cnt++;else S[i].cnt--;
            S[i].low=min(S[i].low,S[i].cnt);
            S[i].high=S[i].cnt-S[i].low;
        }
    }
    int now=0,flag=1;
    sort(S+1,S+1+n,cmp);
    int p=1;
    for(;p<=n&&S[p].cnt>0;p++);
    S[0].high=-inf,S[0].low=-inf;
    for(int i=1;i<p;i++)
    {
        int ff=0,tt=0;
        for(int j=1;j<p;j++)
        {
            if(!vis[j]&&(S[j].low+now>=0))
            {
                ff=1;
                if(S[j].low>S[tt].low)
                {
                    tt=j;
                }
            }
        }
        if(!ff)
        {
            printf("No\n");
            return 0;
        }
        vis[tt]=1;
        now+=S[tt].cnt;
    }
    for(int i=p;i<=n;i++)
    {
        int ff=0,tt=0;
        for(int j=p;j<=n;j++)
        {
            if(!vis[j]&&(S[j].low+now>=0))
            {
                ff=1;
                if(S[j].high>S[tt].high)
                {
                    tt=j;
                }
            }
        }
        if(!ff)
        {
            printf("No\n");
            return 0;
        }
        vis[tt]=1;
        now+=S[tt].cnt;
    }
    if(now==0) printf("Yes\n");else printf("No\n");
    return 0;
}