Example

Input

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


Output

Yes
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector< pair<int,int> > P, N;
  string s;
  for(int i = 0; i < n; ++i){
    cin >> s;
    int m = 1000, t = 0;
    for(int j = 0; j < s.length(); ++j){
      if(s[j] == '(') ++t;
      else --t;
      m = min(m,t);
    }
    if(t >= 0) P.push_back(make_pair(m,t));
    else N.push_back(make_pair(m-t,-t));
  }
  sort(P.begin(), P.end());
  reverse(P.begin(), P.end());
  sort(N.begin(), N.end());
  int t = 0;
  for(int i = 0; i < P.size(); ++i){
    //cout << P[i].first << " " << P[i].second << endl;
    if(t + P[i].first >= 0){
      t += P[i].second;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = 0; i < N.size(); ++i){
    //cout << N[i].first << " " << -N[i].second << endl;
    if(t + N[i].first - N[i].second >= 0){
      t -= N[i].second;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
 
  if(t) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}