Example

Input

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


Output

Yes
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

using P = pair<int, int>;

int main()
{
    int N;
    cin >> N;

    vector<P> value(N);
    for (int i = 0; i < N; i++) {
        int num = 0;
        int mini = 0;
        string s;
        cin >> s;
        for (const char c : s) {
            if (c == '(') {
                num++;
            } else {
                num--;
            }
            mini = min(num, mini);
        }
        value[i] = make_pair(mini, num);
    }
    int sum = 0;
    vector<P> evil;
    for (int i = 0; i < N; i++) {
        if (value[i].first >= 0) {
            sum += value[i].second;
        } else {
            evil.push_back(value[i]);
        }
    }
    vector<P> plus;
    vector<P> minus;
    for (const P& p : evil) {
        if (p.second >= 0) {
            plus.push_back(p);
        } else {
            minus.push_back(p);
        }
    }

    sort(plus.begin(), plus.end(), greater<P>{});
    sort(minus.begin(), minus.end(), [](const P& p1, const P& p2) { return p1.first - p1.second < p2.first - p2.second; });
    for (const P& p : plus) {
        if (p.first + sum < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            sum += p.second;
        }
    }
    for (const P& p : minus) {
        if (p.first + sum < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            sum += p.second;
        }
    }
    if (sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}