Example

Input

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


Output

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

int main() {
    int n;
    cin >> n;
    vector<string> v(n);
    vector<int> mi(n), last(n);
    vector<int> mi_r(n), last_r(n); // from right
    for(int i=0; i<n; ++i) {
        cin >> v[i];
        mi[i] = (v[i][0] == '(' ? 1 : -1);
        int sum = mi[i];
        for(int j=1; j<v[i].size(); ++j) {
            sum += (v[i][j] == '(' ? 1 : -1);
            mi[i] = min(mi[i], sum);
        }
        last[i] = sum;

        mi_r[i] = v[i].back() == ')' ? 1 : -1;
        sum = mi_r[i];
        for(int j=v[i].size()-2; j>=0; --j) {
            sum += (v[i][j] == ')' ? 1 : -1);
            mi_r[i] = min(mi_r[i], sum);
        }
        last_r[i] = sum;
    }
    vector<bool> used(n);
    int now = 0;
    while(true) {
        int next = -1;
        for(int i=0; i<n; ++i) {
            if(used[i]) {
                continue;
            }
            if(now + mi[i] >= 0 && now + last[i] >= now) {
                if(next == -1 || last[i] > last[next]) {
                    next = i;
                }
            }
        }
        if(next == -1) {
            break;
        }
        used[next] = true;
        now += last[next];
    }

    int now2 = 0;
    while(true) {
        int next = -1;
        for(int i=0; i<n; ++i) {
            if(used[i]) {
                continue;
            }
            if(now2 + mi_r[i] >= 0 && now2 + last_r[i] >= now2) {
                if(next == -1 || last_r[i] > last_r[next]) {
                    next = i;
                }
            }
        }
        if(next == -1) {
            break;
        }
        used[next] = true;
        now2 += last_r[next];
    }

    if(count(used.begin(), used.end(), true) == n && now == now2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
