Example

Input

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


Output

Yes
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

const int N=2e6+100;

struct p{
    int a,b;
    int id;
    int type;
}v[N];

bool comp(const p& A,const p& B){
    if(A.type!=B.type) return A.type<B.type;
    if(A.type==2){
        if(A.b!=B.b){
            return A.b<B.b;
        }else{
            return A.a>B.a;
        }
    }
    if(A.type==3){
        return A.a>B.a;
    }
    return A.type<B.type;
}

int main(){
    int n; cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
        int a=0,b=0;
        for(char c:s[i]){
            if(c=='('){
                a++;
            }else{
                if(a>0)a--;
                else b++;
            }
        }
        v[i].id=i+1;
        v[i].a=a; v[i].b=b;
        if(a+b==0){
            v[i].type=0;
        }
        else if(a>0&&b==0){
            v[i].type=1;
        }
        else if(a>0&&b>0&&a-b>=0){
            v[i].type=2;
        }
        else if(a>0&&b>0){
            v[i].type=3;
        }
        else{
            v[i].type=4;
        }
    }
    sort(v,v+n,comp);
    int now=0;
    bool ok=1;
    for(int i=0;i<n;i++){
        if(now-v[i].b<0)ok=0;
        now-=v[i].b;
        now+=v[i].a;
    }
    if(now!=0)ok=0;
    if(!ok){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

