Language: C++

#pragma region template
// clang-format off
#if defined ONLINE_JUDGE
  #pragma GCC target("avx2")
  #pragma GCC optimize("tree-vectorize")
  #define here(...)
  #define com(msg)
  #define watch(...)
  #define watchVec(vec)
  #define local(x)
  #define alter(x,y) y
  #define M_assert(expr) do{if(!expr) vector<int> MLE_(3e8, 0);} while(0)
  #define O_assert(expr) do{if(!expr) while(1) printf("Hello, world!\n");} while(0)
#elif defined LOCAL_JUDGE
  #pragma GCC target("avx2")
  #pragma GCC optimize("tree-vectorize")
  #define here(...)
  #define com(msg)
  #define watch(...)
  #define watchVec(vec)
  #define local(x)
  #define alter(x,y) y
  #define M_assert(expr) assert(expr)
  #define O_assert(expr) assert(expr)
#else
  #define here(...) cerr<<"[Debug] "<<__func__<<"/"<<__LINE__<<" : reached "<<#__VA_ARGS__<<"\n"
  #define com(msg) cerr<<"[Debug] "<<msg<<"\n"
  #define watch(...) dbg1(#__VA_ARGS__,__VA_ARGS__)
  #define watchVec(vec) do{cerr<<#vec<<": ";dbg2(#vec,vec);} while(0)
  #define local(x) do{x} while(0)
  #define alter(x,y) x
  #define M_assert(expr) assert(expr)
  #define O_assert(expr) assert(expr)
#endif

#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <atcoder/all>
namespace ac = atcoder;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rng(i,f,t,s) for(int i : boost::irange(f,t,s))
#define erng(i,f,t,s) for(int i : boost::irange(f,t+(s>0)-(s<0),s))
#define yes(n) cout<<((n)?YES:NO)<<"\n"
#define Sort(v) sort((v).begin(),(v).end())
#define rSort(v) sort((v).rbegin(),(v).rend())
#define Rev(v) reverse((v).begin(),(v).end())
#define Unique(v) (v).erase(unique((v).begin(),(v).end()),(v).end())
#define inarea(p,a,b) (0<=(p.first)&&0<=(p.second)&&(p.first)<(a)&&(p.second)<(b))
#define in_area(y,x,a,b) (0<=(y)&&0<=(x)&&(y)<(a)&&(x)<(b))
#define in_range(x,a,b) ((a)<=(x)&&(x)<(b))

using namespace std;
using Int = boost::multiprecision::cpp_int;

constexpr int           INF   = 1e9;
constexpr long long     LINF  = 1e18;
constexpr double        EPS   = 1e-9;
constexpr char          YES[] = "Yes";
constexpr char          NO[]  = "No";
constexpr int           dy[]  = {1,0,-1,0,1,1,-1,-1};
constexpr int           dx[]  = {0,1,0,-1,-1,1,1,-1};
constexpr pair<int,int> dv[]  = { {1,0},{0,1},{-1,0},{0,-1},{1,-1},{1,1},{-1,1},{-1,-1} };

// --- functions for debugging --- //
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
template<class T>            void dbg1(const char *n, T &&v){cerr<<n<<": "<<v<<"\n";}
template<class S,class... T> void dbg1(const char *n, S &&v, T&&... w){const char *c=strchr(n+1,',');cerr.write(n,c-n)<<": "<<v<<" |";dbg1(c+1,w...);}
template<class P>            void dbg2(const char *n, const P &p){cerr<<"{ "<<p.first<<" "<<p.second<<" } ";}
template<class T>            void dbg2(const char *n, const vector<T> &v){cerr<<"[ ";for(auto &&x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class T>            void dbg2(const char *n, const deque<T> &v){cerr<<"[ ";for(const T &x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class T>            void dbg2(const char *n, const set<T> &v){cerr<<"[ ";for(const T &x:v)cerr<<x<<" ";cerr<<"]\n";}
template<class S,class T>    void dbg2(const char *n, const map<S,T> &m){cerr<<"[ ";for(const pair<S,T> &p:m)cerr<<"{ "<<p.first<<", "<<p.second<<" } ";cerr<<"]\n";}
template<class T>            void dbg2(const char *n, const vector<vector<T>> &v){bool f=false;for(const vector<T> &x:v){if(f)cerr<<string(strlen(n)+2,' ');f=true;dbg2<T>("",x);}}
template<class T>            void dbg2(const char *n, const vector<deque<T>> &v){bool f=false;for(const deque<T> &x:v){if(f)cerr<<string(strlen(n)+2,' ');f=true;dbg2<T>("",x);}}
template<class S,class T>    void dbg2(const char *n, const vector<pair<S,T>> &v){cerr<<"[ ";for(const pair<S,T> &p:v)dbg2<pair<S,T>>("",p);cerr<<"]\n";}
template<class S,class T>    void dbg2(const char *n, const deque<pair<S,T>> &v){cerr<<"[ ";for(const pair<S,T> &p:v)dbg2<pair<S,T>>("",p);cerr<<"]\n";}
#pragma GCC diagnostic pop
// clang-format on
#pragma endregion
// yes/no

#pragma region lib_representative_values
namespace lib {
  /*
    Function that returns the minimum element of the given vector
    usage: min(vec)
    time complexity: O(n)
  */
  template <class T> T min(const vector<T> &vec) {
    return *min_element(vec.begin(), vec.end());
  }

  /*
    Function that returns the maximum element of the given vector
    usage: max(vec)
    time complexity: O(n)
  */
  template <class T> T max(const vector<T> &vec) {
    return *max_element(vec.begin(), vec.end());
  }

  /*
    Function that returns the sum of the elements in given vector
    usage: sum(vec)
    time complexity: O(n)
  */
  template <class T> T sum(const vector<T> &vec) {
    return reduce(vec.begin(), vec.end(), (T) 0);
  }

  /*
    Function that returns the gcd of the elements in given vector
    usage: gcd(vec)
    time complexity: O(n)
  */
  template <class T> T gcd(const vector<T> &vec) {
    T ret = vec[0];
    for (int i = 1; i < static_cast<int>(vec.size()); i++) ret = gcd(ret, vec[i]);
    return ret;
  }

  /*
    Function that returns the lcm of the elements in given vector
    usage: lcm(vec)
    time complexity: O(n)
  */
  template <class T> T lcm(const vector<T> &vec) {
    T ret = vec[0];
    for (int i = 1; i < static_cast<int>(vec.size()); i++) ret = lcm(ret, vec[i]);
    return ret;
  }

  /*
    Function that returns the minimum element of the given set
    usage: min(set)
    time complexity: O(n)
  */
  template <class T> T min(const set<T> &st) {
    return *min_element(st.begin(), st.end());
  }

  /*
    Function that returns the maximum element of the given set
    usage: max(set)
    time complexity: O(n)
  */
  template <class T> T max(const set<T> &st) {
    return *max_element(st.begin(), st.end());
  }

  /*
    Function that returns the sum of the elements in given set
    usage: sum(set)
    time complexity: O(n)
  */
  template <class T> T sum(const set<T> &st) {
    return reduce(st.begin(), st.end(), (T) 0);
  }

  /*
    Function that returns the gcd of the elements in given set
    usage: gcd(set)
    time complexity: O(n)
  */
  template <class T> T gcd(const set<T> &st) {
    class set<T>::iterator it = st.begin();
    T ret                     = (*it);
    for (; it != st.end(); it++) ret = gcd(ret, (*it));
    return ret;
  }

  /*
    Function that returns the lcm of the elements in given set
    usage: lcm(set)
    time complexity: O(n)
  */
  template <class T> T lcm(const set<T> &st) {
    class set<T>::iterator it = st.begin();
    T ret                     = (*it);
    for (; it != st.end(); it++) ret = lcm(ret, (*it));
    return ret;
  }

  /*
    Function that returns the key-value pair whose value is smallest in the given map
    usage: min(map)
    time complexity: O(n)
  */
  template <class S, class T> pair<S, T> min(const map<S, T> &m) {
    pair<S, T> ret = *m.begin();
    for (const pair<S, T> &p : m)
      if (ret.second > p.second) ret = p;
    return ret;
  }

  /*
    Function that returns the key-value pair whose value is smallest in the given map
    usage: max(map)
    time complexity: O(n)
  */
  template <class S, class T> pair<S, T> max(const map<S, T> &m) {
    pair<S, T> ret = *m.begin();
    for (const pair<S, T> &p : m)
      if (ret.second < p.second) ret = p;
    return ret;
  }

}  // namespace lib

using lib::gcd;
using lib::lcm;
using lib::max;
using lib::min;
using lib::sum;
#pragma endregion

#pragma region lib_chmin_chmax
namespace lib {
  /*
    Function that updates the first value if and only if the first valus is less than the second value
    If that is the case, this function returns true
    usage: chmin(max_val, tmp_val)
    output: true or false
    time complexity: O(1)
  */
  template <class S, class T>[[maybe_unused]] bool chmin(S &a, T b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  }

  /*
    Function that updates the first value if and only if the first valus is grater than the second value
    If that is the case, this function returns true
    usage: chmax(max_val, tmp_val)
    output: true or false
    time complexity: O(1)
  */
  template <class S, class T>[[maybe_unused]] bool chmax(S &a, T b) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
}  // namespace lib
#pragma endregion

#pragma region lib_sort_by_second
namespace lib {
  /*
    Functions that sort vector<pair<*,*>> by second key
    usage: sort_by_second(vec)
    time complexity: O(n log n)
  */
  template <class S, class T> void sort_by_second(vector<pair<S, T>> &vec) {
    sort(vec.begin(), vec.end(), [](auto &L, auto &R) {
      return (L.second == R.second) ? (L.first < R.first) : (L.second < R.second);
    });
  }

  /*
    Functions that sort vector<pair<*,*>> by second key (in descending order)
    usage: sort_by_second_r(vec)
    time complexity: O(n log n)
  */
  template <class S, class T> void sort_by_second_r(vector<pair<S, T>> &vec) {
    sort(vec.rbegin(), vec.rend(), [](auto &L, auto &R) {
      return (L.second == R.second) ? (L.first < R.first) : (L.second < R.second);
    });
  }
}  // namespace lib
#pragma endregion

void solve(int N, vector<string> S) {
  vector<pair<int, int>> cnt(N, {0, INF});
  rep(i, N) {
    int &score = cnt[i].first;
    for (auto &&c : S[i]) {
      if (c == '(')
        score++;
      else
        score--;
      if (cnt[i].second > 0)
        cnt[i].second = score;
      else
        lib::chmin(cnt[i].second, score);
    }
  }

  watchVec(cnt);

  int all = 0;
  for (auto &&[a, b] : cnt) {
    all += b;
  }
  if (all != 0) {
    yes(0);
    return;
  }

  lib::sort_by_second_r(cnt);
  int cn = 0;

  for (auto &&[a, b] : cnt) {
    if (cn + b < 0) {
      yes(0);
      return;
    }
    cn += a;
  }

  yes(1);
}

// clang-format off
int main() {
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wunused-result"
  int N;
  scanf("%d",&N);
  vector<string> S(N);
  for(int i = 0 ; i < N ; i++){
    cin >> S[i];
  }
  #pragma GCC diagnostic pop
  solve(N, move(S));
  exit(EXIT_SUCCESS);
}


Compiler output:
a.cc:37:10: fatal error: boost/range/irange.hpp: No such file or directory
   37 | #include <boost/range/irange.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.