Example

Input

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


Output

Yes
#include <bits/stdc++.h>
using namespace std;

int n;
char s[111][111];

int f(vector<int> u, vector<int> b){
    int h = 0;
    while(u.size()){
        int k = max_element(begin(b), end(b)) - begin(b);
        if(h + b[k] < 0) return -1;
        h += u[k];
        u.erase(u.begin() + k);
        b.erase(b.begin() + k);
    }
    return h;
}

string solve(){
    vector<int> up[2], bottom[2];
    for(int i = 0; i < n; ++i){
        int h = 0, b = 0;
        for(char *p = s[i]; *p; ++p){
            *p == '(' ? ++h : --h;
            b = min(b, h);
        }
        if(h >= 0){
            up[0].push_back(h);
            bottom[0].push_back(b);
        } else {
            up[1].push_back(-h);
            bottom[1].push_back(b-h);
        }
    }
    int a = f(up[0],bottom[0]), b = f(up[1],bottom[1]);
    return a == b && a != -1 ? "Yes" : "No";
}

int main(){
    while(cin >> n){
        for(int i = 0; i < n; ++i) cin >> s[i];
        cout << solve() << endl;
    }
}