Language: C++

#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
typedef pair<int,int>pii;
#define fi first
#define se second
const int MN=1e6+5;
int n,lt[MN],rt[MN],a[MN],b[MN];
char S[MN];
struct data{
	int x,y;
	data(int x=0,int y=0):x(x),y(y){}
}A[MN],B[MN];
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++){
		scanf("%s",S+rt[i-1]+1);
		lt[i]=rt[i-1]+1;rt[i]=strlen(S+1);
	}
	reg int tot1=0,tot2=0;
	for(reg int i=1;i<=n;i++){
		reg int tot=0;
		for(reg int j=lt[i];j<=rt[i];j++){
			tot+=(S[j]=='('?1:-1);
			a[i]=min(a[i],tot);
		}
		a[i]=-a[i];b[i]=tot+a[i];
		if(a[i]<=b[i])A[++tot1]=data(a[i],b[i]);
		else B[++tot2]=data(a[i],b[i]);
	}
	sort(A+1,A+1+tot1,[](data a,data b){
		return a.x<b.x;
	});
	reg int res=0;
	for(reg int i=1;i<=tot1;i++){
		if(res<A[i].x)return 0*puts("No");
		res+=A[i].y-A[i].x;
	}
	sort(B+1,B+1+tot2,[](data a,data b){
		return a.y>b.y;
	});
	for(reg int i=1;i<=tot2;i++){
		if(res<B[i].x)return 0*puts("No");
		res+=B[i].y-B[i].x;
	}
	if(res)puts("No");
	else puts("Yes");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   17 |         for(reg int i=1;i<=n;i++){
      |                     ^
a.cc:21:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         reg int tot1=0,tot2=0;
      |                 ^~~~
a.cc:21:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         reg int tot1=0,tot2=0;
      |                        ^~~~
a.cc:22:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   22 |         for(reg int i=1;i<=n;i++){
      |                     ^
a.cc:23:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |                 reg int tot=0;
      |                         ^~~
a.cc:24:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 |                 for(reg int j=lt[i];j<=rt[i];j++){
      |                             ^
a.cc:29:41: error: reference to 'data' is ambiguous
   29 |                 if(a[i]<=b[i])A[++tot1]=data(a[i],b[i]);
      |                                         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:30:32: error: reference to 'data' is ambiguous
   30 |                 else B[++tot2]=data(a[i],b[i]);
      |                                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:32:30: error: reference to 'data' is ambiguous
   32 |         sort(A+1,A+1+tot1,[](data a,data b){
      |                              ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:32:30: error: 'data' has not been declared
   32 |         sort(A+1,A+1+tot1,[](data a,data b){
      |                              ^~~~
a.cc:32:37: error: reference to 'data' is ambiguous
   32 |         sort(A+1,A+1+tot1,[](data a,data b){
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:32:37: error: 'data' has not been declared
   32 |         sort(A+1,A+1+tot1,[](data a,data b){
      |                                     ^~~~
a.cc: In lambda function:
a.cc:33:26: error: request for member 'x' in 'a', which is of non-class type 'int'
   33 |                 return a.x<b.x;
      |                          ^
a.cc:33:30: error: request for member 'x' in 'b', which is of non-class type 'int'
   33 |                 return a.x<b.x;
      |                              ^
a.cc: In function 'int main()':
a.cc:35:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         reg int res=0;
      |                 ^~~
a.cc:36:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |         for(reg int i=1;i<=tot1;i++){
      |                     ^
a.cc:40:30: error: reference to 'data' is ambiguous
   40 |         sort(B+1,B+1+tot2,[](data a,data b){
      |                              ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:40:30: error: 'data' has not been declared
   40 |         sort(B+1,B+1+tot2,[](data a,data b){
      |                              ^~~~
a.cc:40:37: error: reference to 'data' is ambiguous
   40 |         sort(B+1,B+1+tot2,[](data a,data b){
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:11:8: note:                 'struct data'
   11 | struct data{
      |        ^~~~
a.cc:40:37: error: 'data' has not been declared
   40 |         sort(B+1,B+1+tot2,[](data a,data b){
      |                                     ^~~~
a.cc: In lambda function:
a.cc:41:26: error: request for member 'y' in 'a', which is of non-class type 'int'
   41 |                 return a.y>b.y;
      |                          ^
a.cc:41:30: error: request for member 'y' in 'b', which is of non-class type 'int'
   41 |                 return a.y>b.y;
      |                              ^
a.cc: In function 'int main()':
a.cc:43:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(reg int i=1;i<=tot2;i++){
      |                     ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 fro