Example

Input

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


Output

Yes
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
const int MAXN = 110;
char s[MAXN][MAXN];
int l[MAXN], r[MAXN];
int has[MAXN];
int main(){
	int n;
	while(~scanf("%d", &n)){
		memset(has,0,sizeof has);
		memset(l,0,sizeof l);
		memset(r,0,sizeof r);
		for(int i = 1;i <= n; i++){
			scanf("%s", s[i]);
			int len = strlen(s[i]);
			for(int j = 0; j < len; j++){
				if(s[i][j] == '(')
					l[i]++;
				else if(s[i][j] == ')'){
					if(l[i] == 0) r[i]++;
					else l[i]--;
				}
			}
		}
		int flag = 0;
		int sum = 0;
		int tmp,tmpl,tmpr;
		for(int c = 1; c <= n; c++){
			tmp = tmpl = tmpr = -1;
			for(int i = 1; i <= n; i++){
				if(has[i]) continue;
				if(sum >= r[i]){
					if(tmpl < l[i]){
						tmp = i;
						tmpl = l[i];
						tmpr = r[i];
					}
					else if(tmpl == l[i] && tmpr > r[i]){
						tmp = i;
						tmpl = l[i];
						tmpr = r[i];
					}
				}
			}
			if(tmp == -1) {
				flag = 1;
				break;
			}
			has[tmp] = 1;
			sum = sum - tmpr + tmpl;
		}
		if(flag) puts("No");
		else if(sum == 0) puts("Yes");
		else puts("No");
	}
	return 0;
}