Example

Input

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


Output

Yes
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef pair<int, int>P;

int main(void){
    // Your code here!
    int n;
    cin>>n;
    vector<P>left, right;
    int leftSum = 0, rightSum = 0;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        int mn = 0, tmp = 0;
        for(int j=0;j<str.size();j++){
            if(str[j]=='(')tmp++;
            else tmp--;
            mn = min(mn, tmp);
        }
        if(tmp >= 0){
            left.push_back(P(-mn,tmp));
            leftSum+=tmp;
            continue;
        }
        mn=0;
        tmp=0;
        for(int j=str.size()-1;j>=0;j--){
            if(str[j]==')')tmp++;
            else tmp--;
            mn = min(mn, tmp);
        }
        right.push_back(P(-mn,tmp));
        rightSum+=tmp;
    }
    if(leftSum-rightSum!=0){
        cout<<"No"<<endl;
        return 0;
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    for(int i=0, tmp=0;i<left.size();i++){
        if(tmp < left[i].first){
            cout<<"No"<<endl;
            return 0;
        }
        tmp += left[i].second;
    }
    for(int i=0, tmp=0;i<right.size();i++){
        if(tmp < right[i].first){
            cout<<"No"<<endl;
            return 0;
        }
        tmp += right[i].second;
    }
    cout<<"Yes"<<endl;
    return 0;    
}

