Example

Input

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


Output

Yes
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct nod{
int ma,mi,all;
}num[1100];
int n,i,l,j,now;
char s[1100];
bool cmp(nod a,nod b)
{
    if (a.mi!=b.mi) return a.mi>b.mi;
    return a.all>b.all;

}
bool cmp2(nod a,nod b)
{
    if (a.ma!=b.ma) return a.ma>b.ma;
    if (a.mi!=b.mi) return a.mi>b.mi;
    return a.all>b.all;
}
int main()
{
    scanf("%d\n",&n);
    for (i=1;i<=n;i++)
    {
        gets(s); l=strlen(s);
        num[i].mi=10000; num[i].ma=-10000;
        for (j=0;j<l;j++)
        {
            if (s[j]=='(') num[i].all++; else num[i].all--;
            num[i].mi=min(num[i].mi,num[i].all);
        }
        num[i].all=0;
        for (j=l-1;j>=0;j--)
        {
            if (s[j]=='(') num[i].all++; else num[i].all--;
            num[i].ma=max(num[i].ma,num[i].all);
        }
        now+=num[i].all;
    }
    if (now)
    {
        printf("No\n");
        return 0;
    }
    now=0;

    for (i=1;i<=n;i++) if (num[i].mi>=0) now+=num[i].all;

    sort(num+1,num+n+1,cmp);

    for (i=1;i<=n;i++)
    if (num[i].mi<0 && num[i].all>=0)
    {
        if (now+num[i].mi<0)
        {
            printf("No\n");
            return 0;
        }
        now+=num[i].all;
    }

    sort(num+1,num+n+1,cmp2);

    for (i=1;i<=n;i++)
    if (num[i].all<0)
    {
        if (now+num[i].mi<0)
        {
            printf("No\n");
            return 0;
        }
        now+=num[i].all;
    }
    printf("Yes\n");
}