Example

Input

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


Output

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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > left, right;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        int add=0, maxdiff=0;
        for(int j=0; j<(int)s.length(); j++){
            if(s[j]=='(') add++;
            else add--;
            maxdiff = max(maxdiff, -add);
        }
        if(add >= 0){
            left.push_back(make_pair(maxdiff, add));
        }else{
            int add=0, maxdiff=0;
            for(int j=s.length()-1; j>=0; j--){
                if(s[j]==')') add++;
                else add--;
                maxdiff = max(maxdiff, -add);
            }
            right.push_back(make_pair(maxdiff, add));
        }
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());

    int depthl=0;
    bool success = true;
    for(int i=0; i<(int)left.size(); i++){
        if(left[i].first > depthl) success = false;
        depthl += left[i].second;
    }
    int depthr=0;
    for(int i=0; i<(int)right.size(); i++){
        if(right[i].first > depthr) success = false;
        depthr += right[i].second;
    }
    if(depthl != depthr) success = false;
    if(success){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

