Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<PII> plus, minus;
    REP(i, n) {
        string s;
        cin >> s;

        ll now = 0, mi = 0;
        REP(j, s.size()) {
            if(s[j] == '(') now++;
            else now--;
            chmin(mi, now);
        }

        if(now > 0) plus.push_back({mi, now});
        else minus.push_back({mi, now});
    }

    auto solve = [](vector<PII> vp, ll sum) {
        ll sz = vp.size();
        REP(i, sz) {
            if(sum + vp[i].first < 0) {
                return -INF;
            }
            sum += vp[i].second;
        }
        return sum;
    };

    sort(ALL(plus), greater<>());
    ll sum = solve(plus, 0);
    if(sum == -INF) {
        cout << "No" << endl;
        return 0;
    }

    sort(ALL(minus), [](PII l, PII r){
        return l.first - l.second < r.first - r.second;
    });
    sum = solve(minus, sum);
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<PII> plus, minus;
    REP(i, n) {
        string s;
        cin >> s;

        ll now = 0, mi = 0;
        REP(j, s.size()) {
            if(s[j] == '(') now++;
            else now--;
            chmin(mi, now);
        }

        if(now > 0) plus.push_back({mi, now});
        else minus.push_back({mi, now});
    }

    auto solve = [](vector<PII> vp, ll sum) {
        ll sz = vp.size();
        REP(i, sz) {
            if(sum + vp[i].first < 0) {
                return -INF;
            }
            sum += vp[i].second;
        }
        return sum;
    };

    sort(ALL(plus));
    ll sum = solve(plus, 0);
    if(sum == -INF) {
        cout << "No" << endl;
        return 0;
    }

    sort(ALL(minus), [](PII l, PII r){
        return l.first - l.second < r.first - r.second;
    });
    sum = solve(minus, sum);
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Compiler output:
a.cc:14:17: error: '#' is not followed by a macro parameter
   14 | #define dump(...)#include <bits/stdc++.h>
      |                 ^
a.cc:21:27: error: redefinition of 'template<class T> void chmin(T&, const T&)'
   21 | template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
      |                           ^~~~~
a.cc:8:27: note: 'template<class T> void chmin(T&, const T&)' previously declared here
    8 | template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
      |                           ^~~~~
a.cc:22:27: error: redefinition of 'template<class T> void chmax(T&, const T&)'
   22 | template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
      |                           ^~~~~
a.cc:9:27: note: 'template<class T> void chmax(T&, const T&)' previously declared here
    9 | template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
      |                           ^~~~~
a.cc:23:8: error: redefinition of 'struct FastIO'
   23 | struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
      |        ^~~~~~
a.cc:10:8: note: previous definition of 'struct FastIO'
   10 | struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
      |        ^~~~~~
a.cc:23:66: error: conflicting declaration 'int fastiofastio'
   23 | struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
      |                                                                  ^~~~~~~~~~~~
a.cc:10:66: note: previous declaration as 'FastIO fastiofastio'
   10 | struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
      |                                                                  ^~~~~~~~~~~~
a.cc:78:10: error: redefinition of 'const ll INF'
   78 | const ll INF = 1LL<<60;
      |          ^~~
a.cc:29:10: note: 'const ll INF' previously defined here
   29 | const ll INF = 1LL<<60;
      |          ^~~
a.cc:80:5: error: redefinition of 'int main()'
   80 | int main(void) {
      |     ^~~~
a.cc:31:5: note: 'int main()' previously defined here
   31 | int main(void) {
      |     ^~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h: In function 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = main()::<lambda(PII, PII)>]':
/usr/include/c++/14/bits/stl_algo.h:4793:5: error: mangling of 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = main()::<lambda(PII, PII)>]' as '_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIxxESt6vectorIS3_SaIS3_EEEEZ4mainEUlS3_S3_E_EvT_SA_T0_' conflicts with a previous mangle
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: previous mangling 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = main()::<lambda(PII, PII)>]'
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/predefined_ops.h: In function 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare> __gnu_cxx::__ops::__iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]':
/usr/include/c++/14/bits/predefined_ops.h:164:5: error: mangling of 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare> __gnu_cxx::__ops::__iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]' as '_ZN9__gnu_cxx5__ops16__iter_comp_iterIZ4mainEUlSt4pairIxxES3_E_EENS0_15_Iter_comp_iterIT_EES6_' conflicts with a previous mangle
  164 |     __iter_comp_iter(_Compare __comp)
      |     ^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:164:5: note: previous mangling 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare> __gnu_cxx::__ops::__iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]'
/usr/include/c++/14/bits/predefined_ops.h:164:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/move.h: In function 'constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&) [with _Tp = main()::<lambda(PII, PII)>&]':
/usr/include/c++/14/bits/move.h:137:5: error: mangling of 'constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&) [with _Tp = main()::<lambda(PII, PII)>&]' as '_ZSt4moveIRZ4mainEUlSt4pairIxxES1_E_EONSt16remove_referenceIT_E4typeEOS5_' conflicts with a previous mangle
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note: previous mangling 'constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&) [with _Tp = main()::<lambda(PII, PII)>&]'
/usr/include/c++/14/bits/move.h:137:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
/usr/include/c++/14/bits/predefined_ops.h: In constructor 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::_Iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]':
/usr/include/c++/14/bits/predefined_ops.h:150:7: error: mangling of 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::_Iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]' as '_ZN9__gnu_cxx5__ops15_Iter_comp_iterIZ4mainEUlSt4pairIxxES3_E_EC2ES4_' conflicts with a previous mangle
  150 |       _Iter_comp_iter(_Compare __comp)
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:150:7: note: previous mangling 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::_Iter_comp_iter(_Compare) [with _Compare = main()::<lambda(PII, PII)>]'
/usr/include/c++/14/bits/predefined_ops.h:150:7: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
/usr/include/c++/14/bits/stl_algo.h: In function 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]':
/usr/include/c++/14/bits/stl_algo.h:1900:5: error: mangling of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]' as '_ZSt6__sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIxxESt6vectorIS3_SaIS3_EEEENS0_5__ops15_Iter_comp_iterIZ4mainEUlS3_S3_E_EEEvT_SD_T0_' conflicts with a previous mangle
 1900 |     __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:1900:5: note: previous mangling 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]'
/usr/include/c++/14/bits/stl_algo.h:1900:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
/usr/include/c++/14/bits/stl_algo.h: In function 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]':
/usr/include/c++/14/bits/stl_algo.h:1876:5: error: mangling of 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]' as '_ZSt16__introsort_loopIN9__gnu_cxx17__normal_iteratorIPSt4pairIxxESt6vectorIS3_SaIS3_EEEElNS0_5__ops15_Iter_comp_iterIZ4mainEUlS3_S3_E_EEEvT_SD_T0_T1_' conflicts with a previous mangle
 1876 |     __introsort_loop(_RandomAccessIterator __first,
      |     ^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1876:5: note: previous mangling 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]'
/usr/include/c++/14/bits/stl_algo.h:1876:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
/usr/include/c++/14/bits/stl_algo.h: In function 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]':
/usr/include/c++/14/bits/stl_algo.h:1863:5: error: mangling of 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(PII, PII)> >]' as '_ZSt14__partial_sortIN9__gnu_cxx17__normal_i