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++ (Clang 10.0.0) (judge verdict: Wrong Answer)

// C++(Clang 10.0.0)

//GCC用 ナゾです
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assert(x>=0) -> x<0の時異常終了
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>
#include <queue>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(ll i=(min);i<(max);i++)
#define FOReq(i,min,max) for(ll i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(ll i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(ll i=(max);i>=(min);i--)

#define all(vec) (vec).begin(),(vec).end()

const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
//#define br printf("\n");
#define br cout<<"\n";
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll samepair(ll x){return x*(x-1)/2;}
inline void printD(double d){printf("%15.15lf ",d);}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

//番兵　累積和　しゃくとり法　木構造　DP キュー　乱択アルゴリズム　嘘解法　ハッシュ　next_permulation

//課題：DP 木構造　Xor

//多い失敗：小数点以下表示しきれてない　オーバーフロー　そもそも嘘解法 

//Nが10^6 → O(N)かO(N log N)
//Nが10^5 → O(N log N)かO(N log2 N)
//Nが3000 → O(N^2)
//Nが300 → O(N^3)(シンプルな処理)
//Nが100 → O(N^3)
//Nが50 → O(N^4)
//Nが20 → O(2^N)かO(N * 2^N)

ll probA(){
    ll ans;ans=0;
    ll N;N=0;
    
    string S,M;
    
    cin>>S;
    cin>>M;
    
    if(S.size()+1 != M.size())OutputAndReturn0("No");
    
    FOR(i, 0, S.size()){
        if(S[i]!=M[i])OutputAndReturn0("No");
    }
    
    
    OutputAndReturn0("Yes");
    return 0;
}

ll probB(){
    ll ans;ans=0;
    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    
    ll chosen=0;
    ll temp=0;
    
    chosen += min(A,K);
    temp    = min(A,K);
    
    ans+=temp;
    if(chosen==K)OutputAndReturn0(ans);
    
    
    chosen  = min(A+B,K);
    temp    = min(B,K-A);
    
    
    ans+=0;
    if(chosen==K)OutputAndReturn0(ans);
    
    
    
    chosen  = min(A+B+C,K);
    temp    = min(C,K-A-B);
    
    ans+= -1*temp;
    
    
    OutputAndReturn0(ans);
    return 0;
}

ll probC(){
    ll ans;ans=INF;
    ll N,M,X;N=0;
    cin>>N>>M>>X;
    
    ll price[N];
    ll skillup[N][M];
    
    FOR(i, 0, N){
        cin>>price[i];
        FOR(k, 0, M){
            cin>>skillup[i][k];
            //cout<<i<<" "<<k<<endl;
        }
    }
    
    bool gets[N];
    
    ll nowskill[M];
    ll totalprice=0;
    
    FOR(i, 0, pow(2,N)){
        
        FOR(k, 0, N){
            ll bit2k=pow(2,k);
            if(  (i & bit2k) == 0  )gets[k]=false;else gets[k]=true;
        }
        
        FOR(k, 0, M){
            nowskill[k]=0;
        }
        
        totalprice=0;
        FOR(k, 0, N){
            if(gets[k]==false)continue;
            
            FOR(p, 0, M){
                nowskill[p]+=skillup[k][p];
            }
            totalprice+=price[k];
        }
        
        bool OK;
        OK=true;
        FOR(k, 0, M){
            if(nowskill[k]<X)OK=false;
        }
        
        if(OK)ans=min(ans,totalprice);
        
        
    }
    
    
    if(ans==INF)OutputAndReturn0(-1);
    OutputAndReturn0(ans);
    return 0;
}



ll probD(){
    ll ans;ans=0;//町１の事
    ll N,K;
    cin>>N>>K;
    
    ll totele[N];
    FOR(i, 0, N){
        cin>>totele[i];totele[i]--;
    }
    
    bool seen[N];
    FOR(i, 0, N){
        seen[i]=false;
    }
    seen[0]=true;
    
    ll nthtown[N+2];//高々N回の移動でループ
    nthtown[0]=0;
    
    ll howmanymove=INF;
    
        //cout<<"nthtown["<<0<<"] is "<<nthtown[0]<<endl;
    for(ll i=1;i<N+2;i++){
        nthtown[i]=totele[nthtown[i-1]];
        //cout<<"nthtown["<<i<<"] is "<<nthtown[i]<<endl;
        if(i==K){OutputAndReturn0(nthtown[i]+1);}
        if(seen[nthtown[i]]){howmanymove=i; break;}
        seen[nthtown[i]]=true;
    }
    if(howmanymove==INF)OutputAndReturn0("OUT");
    
    //cout<<"c"<<endl;
    
    //一度見たとこまできた
    ll beforeseen;
    for (ll p=howmanymove-1; ; p--) {
        if(nthtown[p]==nthtown[howmanymove]){beforeseen=p;break;}
    }
    
    
    ll loop = howmanymove - beforeseen;
    ll K2   = K           - beforeseen;
    
    ll K3   = K2 % loop;
    
    
    
    
    
    //答えは＋１する！！！！！
    //cout<<"e"<<endl;
    OutputAndReturn0(nthtown[ beforeseen+K3 ] +1);
    return 0;
}




ll probE(){
    ll ans;ans=0;
    ll N;N=0;
    cin>>N;
    OutputAndReturn0(ans);
    return 0;
}







ll probF(){
    ll ans;ans=0;
    ll N;N=0;
    cin>>N;
    
    string S[N];
    inarray(S, 0, N);
    
    ll left[N];
    ll right[N];
    
    
    ll l,r;
    // l=')',  r='('
    FOR(i, 0, N){
        l=0;r=0;
        FOR(k, 0, S[i].size()){
            if(S[i][k]=='('){
                r++;
            }
            else{//  ')'
                if(r<=0)l++;
                else    r--;
            }
        }
        left[i]=l;
        right[i]=r;
        //cout<<l<<" "<<r<<endl;
    }
    //  (((((((((((()))
    
    ll ok1=-1;
    ll ok2=-1;
    FOR(i, 0, N){
        if(left[i]==0){
            if(ok1!=-1){ok2=i;}else ok1=i;
        }
    }
    if(ok1==-1)OutputAndReturn0("No");
    
    ll ok3=-1;
    ll ok4=-1;
    FOR(i, 0, N){
        if(right[i]==0){
            if(ok3!=-1){ok4=i;}else ok3=i;
        }
    }
    
    //cout<<ok1<<" "<<ok2<<" "<<ok3<<" "<<ok4 <<endl;
    
    if(ok3==-1)OutputAndReturn0("No");
    
    if(ok1==ok3 and ok2==-1 and ok4==-1)OutputAndReturn0("No")
    
    
    ll leftsum=0;
    ll rightsum=0;
    FOR(i, 0, N){
        leftsum+=left[i];
        rightsum+=right[i];
    }
    if(leftsum==rightsum){OutputAndReturn0("Yes");}
    else{OutputAndReturn0("No");}
    
    
    OutputAndReturn0(ans);
    return 0;
}

signed main(){
    //cin.tie(0);    //cinとcoutの結び付き解除（cout時にcinの内容を吐き出さなくなる）
    //ios::sync_with_stdio(false);  //coutとprintfの結び付き解除（coutとprintfを同時に使うな！）
    probF();
    //cout<<(ll)200*200*200*200*200;
    return 0;
}