Language: C++

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static util;
using P = pair<int, int>;

class Program {
    static void Main(string[] args) {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        var solver = new Solver(sw);
        // var t = new Thread(solver.solve, 1 << 26); // 64 MB
        // t.Start();
        // t.Join();
        solver.solve();
        sw.Flush();
    }
}

class Solver {
    StreamWriter sw;
    Scan sc;
    void Prt(string a) => sw.WriteLine(a);
    void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
    void Prt(params object[] a) => Prt(string.Join(" ", a));
    public Solver(StreamWriter sw) {
        this.sw = sw;
        this.sc = new Scan();
    }

    public void solve() {
        int n = sc.Int;
        var pl = new List<P>();
        var mn = new List<P>();
        var eq = new List<int>();
        for (int i = 0; i < n; i++)
        {
            var s = sc.Str;
            int dep = 0, min = 0;
            foreach (var item in s)
            {
                if (item == '(') {
                    ++dep;
                }
                else {
                    --dep;
                }
                min = Math.Min(min, dep);
            }
            if (dep > 0) {
                pl.Add(new P(min, dep));
            }
            else if (dep < 0) {
                mn.Add(new P(min - dep, -dep));
            }
            else {
                eq.Add(min);
            }
        }
        pl.Sort();
        pl.Reverse();
        int d1 = 0;
        foreach (var item in pl)
        {
            if (d1 + item.v1 < 0) {
                Prt("No");
                return;
            }
            d1 += item.v2;
        }
        mn.Sort();
        mn.Reverse();
        int d2 = 0;
        foreach (var item in mn)
        {
            if (d2 + item.v1 < 0) {
                Prt("No");
                return;
            }
            d2 += item.v2;
        }
        if (d1 != d2) {
            Prt("No");
            return;
        }
        foreach (var item in eq)
        {
            if (d1 + item < 0) {
                Prt("No");
                return;
            }
        }
        Prt("Yes");

    }
}

class pair<T, U> : IComparable<pair<T, U>> {
    public T v1;
    public U v2;
    public pair() : this(default(T), default(U)) {}
    public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; }
    public int CompareTo(pair<T, U> a) {
        int c = Comparer<T>.Default.Compare(v1, a.v1);
        return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
    }
    public override string ToString() => v1 + " " + v2;
    public void Deconstruct(out T a, out U b) { a = v1; b = v2; }
}
static class util {
    public static readonly int M = 1000000007;
    // public static readonly int M = 998244353;
    public static readonly long LM = 1L << 60;
    public static readonly double eps = 1e-11;
    public static void DBG(string a) => Console.Error.WriteLine(a);
    public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
    public static void DBG(params object[] a) => DBG(string.Join(" ", a));
    public static void Assert(params bool[] conds) {
        if (conds.Any(x => !x)) throw new Exception();
    }
    public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2);
    public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> {
        for (int i = 0; i < a.Count && i < b.Count; i++)
            if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]);
        return a.Count.CompareTo(b.Count);
    }
    public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;
    static readonly int[] dd = { 0, 1, 0, -1 };
    // static readonly string dstring = "RDLU";
    public static P[] adjacents(int i, int j)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).ToArray();
    public static P[] adjacents(int i, int j, int h, int w)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1]))
                                         .Where(p => inside(p.v1, p.v2, h, w)).ToArray();
    public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
    public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w);
    public static Dictionary<T, int> compress<T>(this IEnumerable<T> a)
        => a.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);
    public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union));
    public static T[] inv<T>(this Dictionary<T, int> dic) {
        var res = new T[dic.Count];
        foreach (var item in dic) res[item.Value] = item.Key;
        return res;
    }
    public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; }
    public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; }
    public static T[] copy<T>(this IList<T> a) {
        var ret = new T[a.Count];
        for (int i = 0; i < a.Count; i++) ret[i] = a[i];
        return ret;
    }
    public static void Deconstruct<T>(this IList<T> v, out T a) {
        a = v[0];
    }
    public static void Deconstruct<T>(this IList<T> v, out T a, out T b) {
        a = v[0]; b = v[1];
    }
    public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) {
        a = v[0]; b = v[1]; c = v[2];
    }
    public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) {
        a = v[0]; b = v[1]; c = v[2]; d = v[3];
    }
    public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) {
        a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4];
    }
}

class Scan {
    StreamReader sr;
    public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
    public Scan(string path) { sr = new StreamReader(path); }
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => sr.ReadLine().Trim();
    public pair<T, U> Pair<T, U>() {
        T a; U b;
        Multi(out a, out b);
        return new pair<T, U>(a, b);
    }
    public P P => Pair<int, int>();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
                       : eq<T, long>()   ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>()   ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b) {
        var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]);
    }
    public void Multi<T, U, V>(out T a, out U b, out V c) {
        var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
    }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
        var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
    }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
        var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
    }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Linq;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.IO;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.Threading;
      |       ^~~~~~
a.cc:6:7: error: expected nested-name-specifier before 'System'
    6 | using System.Text;
      |       ^~~~~~
a.cc:7:7: error: expected nested-name-specifier before 'System'
    7 | using System.Text.RegularExpressions;
      |       ^~~~~~
a.cc:8:7: error: expected nested-name-specifier before 'System'
    8 | using System.Diagnostics;
      |       ^~~~~~
a.cc:9:7: error: expected nested-name-specifier before 'static'
    9 | using static util;
      |       ^~~~~~
a.cc:10:11: error: 'pair' does not name a type
   10 | using P = pair<int, int>;
      |           ^~~~
a.cc:13:22: error: 'string' has not been declared
   13 |     static void Main(string[] args) {
      |                      ^~~~~~
a.cc:13:31: error: expected ',' or '...' before 'args'
   13 |     static void Main(string[] args) {
      |                               ^~~~
a.cc:22:2: error: expected ';' after class definition
   22 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main(int*)':
a.cc:14:9: error: 'var' was not declared in this scope
   14 |         var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
      |         ^~~
a.cc:15:13: error: expected ';' before 'solver'
   15 |         var solver = new Solver(sw);
      |             ^~~~~~
a.cc:19:9: error: 'solver' was not declared in this scope
   19 |         solver.solve();
      |         ^~~~~~
a.cc:20:9: error: 'sw' was not declared in this scope
   20 |         sw.Flush();
      |         ^~
a.cc: At global scope:
a.cc:25:5: error: 'StreamWriter' does not name a type
   25 |     StreamWriter sw;
      |     ^~~~~~~~~~~~
a.cc:26:5: error: 'Scan' does not name a type
   26 |     Scan sc;
      |     ^~~~
a.cc:27:14: error: 'string' has not been declared
   27 |     void Prt(string a) => sw.WriteLine(a);
      |              ^~~~~~
a.cc:27:27: error: invalid pure specifier (only '= 0' is allowed) before 'sw'
   27 |     void Prt(string a) => sw.WriteLine(a);
      |                           ^~
a.cc:28:10: error: variable or field 'Prt' declared void
   28 |     void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
      |          ^~~
a.cc:28:10: error: expected ';' at end of member declaration
   28 |     void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
      |          ^~~
      |             ;
a.cc:28:13: error: expected unqualified-id before '<' token
   28 |     void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
      |             ^
a.cc:29:14: error: 'params' has not been declared
   29 |     void Prt(params object[] a) => Prt(string.Join(" ", a));
      |              ^~~~~~
a.cc:29:30: error: expected ',' or '...' before 'a'
   29 |     void Prt(params object[] a) => Prt(string.Join(" ", a));
      |                              ^
a.cc:29:36: error: invalid pure specifier (only '= 0' is allowed) before 'Prt'
   29 |     void Prt(params object[] a) => Prt(string.Join(" ", a));
      |                                    ^~~
a.cc:30:11: error: expected ':' before 'Solver'
   30 |     public Solver(StreamWriter sw) {
      |           ^~~~~~~
      |           :
a.cc:30:31: error: expected ')' before 'sw'
   30 |     public Solver(StreamWriter sw) {
      |                  ~            ^~~
      |                               )
a.cc:35:11: error: expected ':' before 'void'
   35 |     public void solve() {
      |           ^~~~~
      |           :
a.cc:100:2: error: expected ';' after class definition
  100 | }
      |  ^
      |  ;
a.cc: In member function 'void Solver::solve()':
a.cc:36:17: error: 'sc' was not declared in this scope
   36 |         int n = sc.Int;
      |                 ^~
a.cc:37:9: error: 'var' was not declared in this scope
   37 |         var pl = new List<P>();
      |         ^~~
a.cc:38:13: error: expected ';' before 'mn'
   38 |         var mn = new List<P>();
      |             ^~
a.cc:39:13: error: expected ';' before 'eq'
   39 |         var eq = new List<int>();
      |             ^~
a.cc:42:17: error: expected ';' before 's'
   42 |             var s = sc.Str;
      |                 ^
a.cc:44:26: error: expected ')' before 'item'
   44 |             foreach (var item in s)
      |                          ^~~~
a.cc:44:21: note: to match this '('
   44 |             foreach (var item in s)
      |                     ^
a.cc:44:13: error: 'foreach' was not declared in this scope
   44 |             foreach (var item in s)
      |             ^~~~~~~
a.cc:55:17: error: 'pl' was not declared in this scope
   55 |                 pl.Add(new P(min, dep));
      |                 ^~
a.cc:55:28: error: expected type-specifier before 'P'
   55 |                 pl.Add(new P(min, dep));
      |                            ^
a.cc:58:17: error: 'mn' was not declared in this scope; did you mean 'min'?
   58 |                 mn.Add(new P(min - dep, -dep));
      |                 ^~
      |                 min
a.cc:58:28: error: expected type-specifier before 'P'
   58 |                 mn.Add(new P(min - dep, -dep));
      |                            ^
a.cc:61:17: error: 'eq' was not declared in this scope
   61 |                 eq.Add(min);
      |                 ^~
a.cc:64:9: error: 'pl' was not declared in this scope
   64 |         pl.Sort();
      |         ^~
a.cc:67:22: error: expected ')' before 'item'
   67 |         foreach (var item in pl)
      |                      ^~~~
a.cc:67:17: note: to match this '('
   67 |         foreach (var item in pl)
      |                 ^
a.cc:67:9: error: 'foreach' was not declared in this scope
   67 |         foreach (var item in pl)
      |         ^~~~~~~
a.cc:75:9: error: 'mn' was not declared in this scope; did you mean 'n'?
   75 |         mn.Sort();
      |         ^~
      |         n
a.cc:78:22: error: expected ')' before 'item'
   78 |         foreach (var item in mn)
      |                      ^~~~
a.cc:78:17: note: to match this '('
   78 |         foreach (var item in mn)
      |                 ^
a.cc:87:17: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   87 |             Prt("No");
      |                 ^~~~
      |                 |
      |                 const char*
a.cc:27:21: note:   initializing argument 1 of 'void Solver::Prt(int)'
   27 |     void Prt(string a) => sw.WriteLine(a);
      |              ~~~~~~~^
a.cc:90:22: error: expected ')' before 'item'
   90 |         foreach (var item in eq)
      |                      ^~~~
a.cc:90:17: note: to match this '('
   90 |         foreach (var item in eq)
      |                 ^
a.cc:97:13: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   97 |         Prt("Yes");
      |             ^~~~~
      |             |
      |             const char*
a.cc:27:21: note:   initializing argument 1 of 'void Solver::Prt(int)'
   27 |     void Prt(string a) => sw.WriteLine(a);
      |              ~~~~~~~^
a.cc: At global scope:
a.cc:102:7: error: 'pair' is not a class template
  102 | class pair<T, U> : IComparable<pair<T, U>> {
      |       ^~~~
a.cc:102:12: error: 'T' was not declared in this scope
  102 | class pair<T, U> : IComparable<pair<T, U>> {
      |            ^
a.cc:102:15: error: 'U' was not declared in this scope
  102 | class pair<T, U> : IComparable<pair<T, U>> {
      |               ^
a.cc:102:31: error: expected template-name before '<' token
  102 | class pair<T, U> : IComparable<pair<T, U>> {
      |                               ^
a.cc:102:31: error: expected '{' before '<' token
a.cc:102:31: error: expected unqualified-id before '<' token
a.cc:115:11: error: expected ':' before 'static'
  115 |     public static readonly int M = 1000000007;
      |           ^~~~~~~
      |           :
a.cc:115:19: error: 'readonly' does not name a type
  115 |     public static readonly int M = 1000000007;
      |                   ^~~~~~~~
a.cc:117:11: error: expected ':' before 'static'
  117 |     public static readonly long LM = 1L << 60;
      |           ^~~~~~~
      |           :
a.cc:117:19: error: 'readonly' does not name a type
  117 |     public static readonly long LM = 1L << 60;
      |                   ^~~~~~~~
a.cc:118:11: error: expected ':' before 'static'
  118 |     public static readonly double eps = 1e-11;
      |           ^~~~~~~
      |           :
a.cc:118:19: error: 'readonly' does not name a type
  118 |     public static readonly double eps = 1e-11;
      |                   ^~~~~~~~
a.cc:119:11: error: expected ':' before 'static'
  119 |     public static void DBG(string a) => Console.Error.WriteLine(a);
      |           ^~~~~~~
      |           :
a.cc:119:28: error: 'string' has not been declared
  119 |     public static void DBG(string a) => Console.Error.WriteLine(a);
      |                            ^~~~~~
a.cc:119:41: error: invalid pure specifier (only '= 0' is allowed) before 'Console'
  119 |     public static void DBG(string a) => Console.Error.WriteLine(a);
      |                                         ^~~~~~~
a.cc:119:24: error: initializer specified for static member function 'static void util::DBG(int)'
  119 |     public static void DBG(string a) => Console.Error.WriteLine(a);
      |                        ^~~
a.cc:120:11: error: expected ':' before 'static'
  120 |     public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
      |           ^~~~~~~
      |           :
a.cc:120:24: error: variable or field 'DBG' declared void
  120 |     public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
      |                        ^~~
a.cc:120:24: error: expected ';' at end of member declar