Problem:
Score : 600 points

Problem Statement

A bracket sequence is a string that is one of the following:

An empty string;

The concatenation of (, A, and ) in this order, for some bracket sequence A ;

The concatenation of A and B in this order, for some non-empty bracket sequences A and B /

Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?

Constraints

1 \leq N \leq 10^6

The total length of the strings S_i is at most 10^6.

S_i is a non-empty string consisting of ( and ).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.

Sample Input 1

2
)
(()

Sample Output 1

Yes

Concatenating (() and ) in this order forms a bracket sequence.

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

4
((()))
((((((
))))))
()()()

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

/*
Read the question and constraints carefully .Take pen and paper and start solving.
write it down
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define pi acos(-1.0)/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    int n,i,j,o,c,tot=0,k;

    cin>>n;

    string s;
    pair<int,string> p[n];

    rep(i,0,n)
    {
        cin>>s;
        p[i].second = s;

        tot += s.size();

        for(j=o=c=0;j<s.size();++j)
        {
            if(s[j]=='(')
                ++o;
            else
                ++c;
        }

        if(c==0)
            p[i].first = 5;
        else if(o==0)
            p[i].first = 1;
        else if(o>c)
            p[i].first = 4;
        else if(c>o)
            p[i].first = 3;
        else
            p[i].first = p[i].first=4;

    }

    sort(p,p+n,greater<pair<int,string>>());

     string ans(tot,'a');



    k=0;
    for(i=0;i<n;++i)
    {
        s = p[i].second;

        for(j=0;j<s.size();++j,++k)
        {
            ans[k] = s[j];
        }
    }


    //cout<<ans<<"\n";

    for(i=o=c=0;i<tot;++i)
    {
        if(ans[i]=='(')
            ++o;
        else
            --o;

        if(o<0)
        {
            cout<<"No";
            return 0;
        }
    }


    if(o==0)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}