Example

Input

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


Output

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

using P = pair<int,int>;
using ll = long long int;

int main() {
    int n;
    cin >> n;
    vector<string> str(n);
    for(int i=0;i<n;i++){
        cin >> str[i];
    }
    vector<P> v[2];
    for(int i=0;i<n;i++){
        int cnt = 0, mi = 0;
        for(int j=0;j<int(str[i].size());j++){
            if(str[i][j] == '(') cnt++;
            else cnt--;
            mi = min(mi, cnt);
        }
        if(cnt > 0) v[0].push_back(P(mi,cnt));
        else v[1].push_back(P(cnt-mi,cnt));
    }
    sort(v[0].rbegin(), v[0].rend());
    sort(v[1].rbegin(),v[1].rend());

    int x = 0;
    bool ok = true;
    for(auto p : v[0]){
        if(x+p.first < 0) ok = false;
        x += p.second;
    }
    for(auto p : v[1]){
        if(x-(p.first-p.second) < 0) ok = false;
        x += p.second;
    }
    if(x != 0) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}
