Example

Input

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


Output

Yes
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
typedef tuple<int,int> T; //'('cnt, ')'cnt

int main(){
    int N;
    cin>>N;
    vector<T> V;
    int L=0,R=0,cnt=0;;
    for(int i=0;i<N;i++){
        string S;
        cin>>S;
        int l=0,r=0;
        for(auto c:S){
            if(c=='('){
                l++;
            }else{
                if(l)l--;
                else r++;
            }
        }
        if(l||r) V.emplace_back(r,l);
        else cnt++;
    }
    sort(V.begin(), V.end());
    string ans;
    while(true){
        bool update = false;
        for(auto &v:V){
            int r,l;
            tie(r,l)=v;
            if(l==1000000&&r==1000000) continue;
            if(r<=L&&l>=r){
                L-=r;
                L+=l;
                v=T(1000000,1000000);
                update=true;
                cnt++;
            }
        }
        if(!update) break;
    }
    for(auto &v:V){
        int r,l;
        tie(r,l)=v;
        v=T(l,r);
    }
    while(true){
        bool update = false;
        for(auto &v:V){
            int l,r;
            tie(l,r)=v;
            if(l==1000000&&r==1000000) continue;
            if(l<=R&&r>=l){
                R-=l;
                R+=r;
                v=T(1000000,1000000);
                update=true;
                cnt++;
            }
        }
        if(!update) break;
    }
    if(L==R&&N==cnt){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}