E.cc

#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<pair<int,int>> ps;
    for(int i = 0; i < N; ++i) {
        string line;
        cin >> line;
        int open = 0, close = 0;
        for(char c : line) {
            if(c == '(') {
                ++open;
            } else if(c == ')') {
                if(open > 0) {
                    --open;
                } else {
                    ++close;
                }
            }
        }
        ps.push_back(make_pair(open, close));
    }
    vector<bool> used(N, false);
    int sum = 0;
    bool can = true;
    for(int i = 0; i < N; ++i) {
        int candidate = -1;
        int cand_sum = -1;
        for(int j = 0; j < N; ++j) {
            if(used[j]) continue;
            if(sum < ps[j].second) continue;
            const int tmp = sum - ps[j].second + ps[j].first;
            if(tmp > cand_sum) {
                candidate = j;
                cand_sum = tmp;
            }
        }
        if(candidate == -1) {
            can = false;
            break;
        }
        sum = cand_sum;
        used[candidate] = true;
    }
    if(sum != 0) can = false;
    cout << (can ? "Yes" : "No") << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}