Example

Input

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


Output

Yes
#include<bits/stdc++.h>
using namespace std;

bool ok(vector< tuple< int, int > >& obj)
{
  int now = 0;
  for(auto v : obj) {
    if(now + get< 0 >(v) < 0) return(false);
    now += get< 1 >(v);
  }
  return(true);
}

int main()
{
  int N;
  cin >> N;
  
  vector< tuple< int, int > > curr, revv;
  while(N--) {
    string S;
    cin >> S;

    int height = 0, cnt = 0;
    for(char c : S) {
      if(c == '(') ++cnt;
      else         --cnt;
      height = min(height, cnt);
    }
    int revheight = 0, revcnt = 0;
    reverse(S.begin(), S.end());
    for(char c : S) {
      if(c == ')') ++revcnt;
      else         --revcnt;
      revheight = min(revheight, revcnt);
    }
    if(cnt >= 0) {
      curr.emplace_back(height, cnt);
    } else {
      revv.emplace_back(revheight, revcnt);
    }
  }
  sort(curr.rbegin(), curr.rend());
  sort(revv.rbegin(), revv.rend());

  bool flag = ok(curr) & ok(revv);
  int csum = 0, rsum = 0;
  for(auto v : curr) csum += get< 1 >(v);
  for(auto v : revv) rsum += get< 1 >(v);
  flag &= csum == rsum;
  if(flag) cout << "Yes" << endl;
  else     cout << "No"  << endl;
}