Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  if(n == 1){
    ll sum = 0;
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
      if(s[i] =='(')sum++;
      else sum--;
      if(sum < 0){cout<<"No"<<endl;return 0;}
    }
    if(s[0] == '(' && s.back() == ')' && sum == 0){
      cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
    return 0;
  }




  ll sum = 0;

  vector<pair<ll,pair<ll,ll>>>plmi,cenmae;
  vector<pair<ll,ll>>minus;
  ll pl = 0;
  bool fl = false,fl2 = false;;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    ll now = 0;
    ll mi = 0;
    for(int j=0;j<s.size();j++){
      if(s[j] == '('){
	now++;sum++;
      }else{
	now--;sum--;
      }
      mi = min(mi,now);
    }
    if(s[0] =='(' && s.back() == ')'){
      if(mi < 0){
	if(now>=0){
	  cenmae.pb(mp(now+mi,mp(now,mi)));
	}else{
	  minus.pb(mp(now,mi));
	}
      }else{
	pl += now;
      }
    }else if(s[0] == '('){
      if(mi < 0){
	if(now > 0){
	  cenmae.pb(mp(now+mi,mp(now,mi)));
	}else{
	  cenmae.pb(mp(now,mi));
	}
      }else pl += now;
    }else if(s.back() == ')'){
      if(mi < 0){
	if(now >= 0){
	  cenmae.pb(mp(now+mi,mp(now,mi)));
	}else{
	  minus.pb(mp(now,mi));
	}
      }else{
	cenmae.pb(mp(now+mi,mp(now,mi)));
      }
    }else{
      cenmae.pb(mp(now+mi,mp(now,mi)));
    }
  }
  if(sum){
    cout<<"No"<<endl;
  }else{
    if(pl == 0 && minus.size() == 0 && cenmae.size() == 0){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(pl == 0 || minus.size() == 0){
      cout<<"No"<<endl;
      return 0;
    }
    sort(ALL(minus),greater<pair<ll,ll>>());
    sort(ALL(cenmae),greater<pair<ll,pair<ll,ll>>>());
    for(auto a:cenmae){
      // cout<<pl<<" "<<a.F<<" "<<a.S<<endl;
      if(pl < -a.S.S){
	cout<<"No"<<endl;
	return 0;
      }
      pl += a.S.F;
    }
    for(auto a:minus){
      // cout<<pl<<" "<<a.F<<" "<<a.S<<endl;
      if(pl < -a.S){
	cout<<"No"<<endl;
	return 0;
      }
      pl += a.F;
    }
    cout<<"Yes"<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:72:20: error: no matching function for call to 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::push_back(std::pair<long long int, long long int>)'
   72 |           cenmae.pb(mp(now,mi));
      |           ~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >; value_type = std::pair<long long int, std::pair<long long int, long long int> >]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'const std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::value_type&' {aka 'const std::pair<long long int, std::pair<long long int, long long int> >&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >; value_type = std::pair<long long int, std::pair<long long int, long long int> >]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::value_type&&' {aka 'std::pair<long long int, std::pair<long long int, long long int> >&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~