Example

Input

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


Output

Yes
#include "bits/stdc++.h"

using namespace std;

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

    int N;
    cin >> N;
    vector<string> s(N);
    vector<int> mi(N, 0), sum(N);
    int total = 0;
    for (int i = 0; i < N; i++)
    {
        int cnt = 0;
        cin >> s[i];
        for (int j = 0; j < (int)s[i].length(); j++)
        {
            if (s[i][j] == '(')
                cnt++;
            else
                cnt--;
            mi[i] = min(mi[i], cnt);
        }
        sum[i] = cnt;
        total += cnt;
    }
    if (total != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    vector<bool> used(N, false);
    for (int i = 0; i < N; i++)
    {
        if (mi[i] >= 0 && sum[i] >= 0)
        {
            total += sum[i];
            used[i] = true;
        }
    }
    while (true)
    {
        bool update = false;
        for (int i = 0; i < N; i++)
        {
            if (used[i])
                continue;
            if (sum[i] >= 0 && total + mi[i] >= 0)
            {
                total += sum[i];
                used[i] = true;
                update = true;
            }
        }
        if (!update)
            break;
    }
    for (int i = 0; i < N; i++)
    {
        if (used[i])
            continue;
        int cnt = 0;
        mi[i] = 0;
        sum[i] = 0;
        reverse(s[i].begin(), s[i].end());
        for (int j = 0; j < (int)s[i].length(); j++)
        {
            if (s[i][j] == ')')
                cnt++;
            else
                cnt--;
            mi[i] = min(mi[i], cnt);
        }
        sum[i] = cnt;
    }
    total = 0;
    for (int i = 0; i < N; i++)
    {
        if (used[i])
            continue;
        if (mi[i] >= 0 && sum[i] >= 0)
        {
            total += sum[i];
            used[i] = true;
        }
    }
    while (true)
    {
        bool update = false;
        for (int i = 0; i < N; i++)
        {
            if (used[i])
                continue;
            if (sum[i] >= 0 && total + mi[i] >= 0)
            {
                total += sum[i];
                used[i] = true;
                update = true;
            }
        }
        if (!update)
            break;
    }
    for (int i = 0; i < N; i++)
    {
        if (!used[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

