Example

Input

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


Output

Yes
#include <bits/stdc++.h>

using namespace std;

int N;
vector<pair<int, int>> xs, ys;
vector<bool> vis;

int main() {

  cin >> N;
  vector<pair<int, int>> ls, rs;
  for(int i=0; i<N; i++) {
    string S; cin >> S;
    int M = S.size();
    int mini = 0, cnt = 0;
    for(int j=0; j<M; j++) {
      if(S[j] == '(') cnt++;
      else cnt--;
      mini = min(mini, cnt);
    }
    if(cnt >= 0)
      ls.emplace_back(mini, cnt);

    cnt = 0, mini = 0;
    for(int j=M-1; j>=0; j--) {
      if(S[j] == ')') cnt++;
      else cnt--;
      mini = min(mini, cnt);
    }
    if(cnt > 0)
      rs.emplace_back(mini, cnt);
  }

  sort(ls.begin(), ls.end(), [&](pair<int, int> const& l, pair<int, int> const& r) { return l.first != r.first ? l.first > r.first : l.second > r.second; });
  sort(rs.begin(), rs.end(), [&](pair<int, int> const& l, pair<int, int> const& r) { return l.first != r.first ? l.first > r.first : l.second > r.second; });

  int sum1 = 0;
  bool ok = 1;
  for(int i=0; i<ls.size(); i++) {
    if(sum1 + ls[i].first < 0) {
      ok = 0;
    }
    sum1 += ls[i].second;
  }

  int sum2 = 0;

  for(int i=0; i<rs.size(); i++) {
    if(sum2 + rs[i].first < 0) {
      ok = 0;
    }
    sum2 += rs[i].second;
  }

  cout << (ls.size() + rs.size() == N && ok && sum1 == sum2 ? "Yes" : "No") << endl;

  return 0;
}