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)

// Author: Zark84010 (Aditya Ranjan)

#include <bits/stdc++.h>
 
using namespace std;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
 
#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)
 
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
 
const int INF = 9e18;
// const int N = 1e9 + 7;
const int N = 998244353;
const double eps = 1e-9;
 
const auto start_time = std::chrono::high_resolution_clock::now();
 
void zark() {
  #ifdef ZARK
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time - start_time;
    cerr << "Time Taken : " << diff.count() << "s\n";
  #endif
}
 
#ifdef ZARK
  #include "/home/aranjan/Desktop/CP/header.h"
  #else
  #define dbg(args...)
#endif

/* ------------------ Actual Coding Starts ------------------ */

// bool cmp(pair<string, int> p1, pair<string, int> p2) {
// 	if(p1.S < p2.S) return ;
// 	else if(p1.S > p2.S) return false;

// }

bool okk(string s) {
	int n = sz(s);
	int ss = 0;
	fo(i, n) {
		if(s[i] == '(') ss++;
		else ss--;
		if(ss < 0) return false;
	}
	return ss == 0;
}

string reduce(string s) {
	string ans;
	int n = sz(s);
	fo(i, n) {
		if(sz(ans) > 0 && ans.back() == '(' && s[i] == ')') {
			ans.pop_back();
		}
		else ans.pb(s[i]);
	}
	return ans;
}

void solve() {
	int n;
	cin >> n;
	vector<string> v(n);
	fo(i, n) cin >> v[i], v[i] = reduce(v[i]);
	vpii a(n);
	fo(i, n) {
		bool ok1 = true, ok2 = true;
		tr(v[i], it) ok1 &= *it == '(', ok2 &= *it == ')';
		if(ok1) a[i].F = -1;
		else if(ok2) a[i].F = 1;
		else a[i].F = 0;
		a[i].S = i;
	}
	sort(all(a));
	string ans = "";
	fo(i, n) ans += v[a[i].S];
	if(okk(ans)) cout << "Yes\n";
	else cout << "No\n";
}

int32_t main() {
  fastio;
  #ifdef ZARK
  freopen("input.in", "r", stdin);
  #endif
 
  // freopen("txt.in", "r", stdin);
  // freopen("txt.out", "w", stdout);
  // cout << fixed << setprecision(35);
 
  solve();
  zark();
  return 0;
}