Example

Input

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


Output

Yes
#include <bits/stdc++.h>
#define lid (id<<1)
#define rid (id<<1|1)
using namespace std;

typedef long long LL;
const int N = 1e2 + 10;

int n;
char s[N];
int min_x[N],f[N],sum = 0;
int p[N];

bool cmp(int i,int j)
{
    if(min_x[p[i]] == 0)
    {
        return true;
    }
    if(min_x[p[j]] == 0)
    {
        return false;
    }

    if(f[p[i]] >= 0)
    {
        if(f[p[j]] < 0 || min_x[p[i]] > min_x[p[j]])
          return true;
        else
          return false;
    }

    if(f[p[j]] >= 0)
    {
        return false;
    }

    return true;
}

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        int l;
        scanf("%s",s + 1);
        l = strlen(s + 1);
        f[i] = 0;min_x[i] = 0;
        for(int j = 1;j <= l;j++)
        {
            f[i] += s[j] == '(' ? 1 : -1;
            min_x[i] = min(min_x[i],f[i]);
        }
        sum += f[i];
  //      cout<<f[i]<<" "<<min_x[i]<<endl;
    }
    if(sum != 0)
    {
        printf("No\n");
        return 0;
    }

    int tot = 0;
    bool use[N];
    memset(use,0,sizeof(use));

    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            if( (min_x[j] == 0 && !use[j]) || (f[j] >= 0 && tot + min_x[j] >= 0 && !use[j]) )
            {
                tot+=f[j];
                use[j] = true;
            }
        }
    }

    int f1[N],f2[N],m = 0,cm = 0;
    for(int i = 1;i <= n;i++)
    if(!use[i])
    {
        if(f[i] >= 0)
        {
            printf("No\n");
            return 0;
        }
        m++;
        f1[m] = -1 * f[i];
        f2[m] = -1 * min_x[i];
    }

    int now = 0;
    for(int i = 1;i <= m;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            if(now + f1[j] >= f2[j])
            {
                now += f1[j];
                f2[j] = 10000;
            }
        }
    }

    if(tot == now) printf("Yes\n");
    else printf("No\n");

	return 0;
}