stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	/*bool operator<(node b)const{

		return x-y>b.x-b.y;

	}*/

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

		//s0+=l-r;

	}

	//if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202473285908759x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int x,y;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201154281187376x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int l,r;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].r)

			return puts("No"),0;

		//le-=a[i].y-a[i].x;

		le-=a[i].r,le+=a[i].l;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201154843057738x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	bool operator<(node b)const{

		return x-y>b.x-b.y;

	}

}a[1000005];

char s[1000005];

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l and r)ri+=r;

		else if(l and !r)le+=l;

		else a[i]=(node){l,r};	

		s0+=l-r;

	}

	if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+n);

	for(int i=1;i<=n;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.198766627131127x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	bool operator<(node b)const{

		return x-y>b.x-b.y;

	}

}a[1000005];

char s[1000005];

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l and r)ri+=r;

		else if(l and !r)le+=l;

		else a[i]=(node){l,r};	

		s0+=l-r;

	}

	if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+n);

	for(int i=1;i<=n;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.199466464760425x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	/*bool operator<(node b)const{

		return x-y>b.x-b.y;

	}*/

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

		//s0+=l-r;

	}

	//if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.198832871646798x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	/*bool operator<(node b)const{

		return x-y>b.x-b.y;

	}*/

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

		//s0+=l-r;

	}

	//if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202473285908759x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int x,y;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201154281187376x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int l,r;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].r)

			return puts("No"),0;

		//le-=a[i].y-a[i].x;

		le-=a[i].r,le+=a[i].l;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201154843057738x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

struct node{

	int l,r;

}a[maxn];

int tot;

char s[maxn];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,ln,rn,l,r;

	int i,j;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)rn+=r;

		else if(l&&!r)ln+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)

			return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	bool operator<(node b)const{

		return x-y>b.x-b.y;

	}

}a[1000005];

char s[1000005];

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l and r)ri+=r;

		else if(l and !r)le+=l;

		else a[i]=(node){l,r};	

		s0+=l-r;

	}

	if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+n);

	for(int i=1;i<=n;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202920512145802x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	bool operator<(node b)const{

		return x-y>b.x-b.y;

	}

}a[1000005];

char s[1000005];

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l and r)ri+=r;

		else if(l and !r)le+=l;

		else a[i]=(node){l,r};	

		s0+=l-r;

	}

	if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+n);

	for(int i=1;i<=n;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2036209089548535x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	/*bool operator<(node b)const{

		return x-y>b.x-b.y;

	}*/

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	n=read();

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else{

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

		//s0+=l-r;

	}

	//if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202986809591739x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

ll read(){

	ll a=0,b=getchar(),c=1;

	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();

	while(isdigit(b))a=a*10+b-'0',b=getchar();

	return a*c;

}

const ll mod=998244353;

ll n,ri,le,s0,f[1000005];

struct node{

	int x,y;

	/*bool operator<(node b)const{

		return x-y>b.x-b.y;

	}*/

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		ll l=0,r=0;

		scanf("%s",s+1);

		for(int j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

		//s0+=l-r;

	}

	//if(s0!=0)return puts("No"),0;

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.206630132594048x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int x,y;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.x-a.y>b.x-b.y;

}

int main(){

	//n=read();

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].y)

			return puts("No"),0;

		le-=a[i].y-a[i].x;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.205310073970011x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,ri,le;

struct node{

	int l,r;

}a[1000005];

int tot;

char s[1000005];

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int i,j;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		int l=0,r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++)

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		if(!l&&r)ri+=r;

		else if(l&&!r)le+=l;

		else if(l&&r)a[++tot]=(node){l,r};	

	}

	sort(a+1,a+1+tot,cmp);

	for(int i=1;i<=tot;i++){

		if(le<a[i].r)

			return puts("No"),0;

		//le-=a[i].y-a[i].x;

		le-=a[i].r,le+=a[i].l;

	}

	if(le!=ri)puts("No");

	else puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.205310636289315x):
#include <cstdio>

#include <algorithm>

#define maxn 1000010

using namespace std;

char s[maxn];

struct node{

	int l,r;

}a[maxn];

int tot;

int cmp(node a,node b){

	return a.l-a.r>b.l-b.r;

}

int main(){

	int n,i,j,l,r,ln,rn;

	ln=rn=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++){

		l=r=0;

		scanf("%s",s+1);

		for(j=1;s[j];j++){

			if(s[j]=='(')l++;

			else if(s[j]==')'){

				if(l)l--;

				else r++;

			}

		}

		if(l&&!r)ln+=l;

		else if(!l&&r)rn+=r;

		else if(l&&r) a[++tot]=(node){l,r};

	}

	sort(a+1,a+1+tot,cmp);

	for(i=1;i<=tot;i++){

		if(ln<a[i].r)return printf("No\n")*0;

		ln-=a[i].r,ln+=a[i].l;

	}

	if(ln!=rn)return printf("No\n")*0;

	printf("Yes\n");

	return 0;

}