Problem:
Score : 600 points

Problem Statement

A bracket sequence is a string that is one of the following:

An empty string;

The concatenation of (, A, and ) in this order, for some bracket sequence A ;

The concatenation of A and B in this order, for some non-empty bracket sequences A and B /

Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?

Constraints

1 \leq N \leq 10^6

The total length of the strings S_i is at most 10^6.

S_i is a non-empty string consisting of ( and ).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.

Sample Input 1

2
)
(()

Sample Output 1

Yes

Concatenating (() and ) in this order forms a bracket sequence.

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

4
((()))
((((((
))))))
()()()

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC167
{
    /// <summary>
    /// 
    /// </summary>
    static class F
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var plus = new List<K>(n);
            var minus = new List<K>(n);

            for (int i = 0; i < n; i++)
            {
                var s = Next();
                var open = 0;
                var close = 0;
                for (int j = 0; j < s.Length; j++)
                {
                    var c = s[j];
                    if (c == '(')
                    {
                        open++;
                    }
                    else
                    {
                        if (open > 0)
                        {
                            open--;
                        }
                        else
                        {
                            close++;
                        }
                    }

                }

                if(open >= close)
                {
                    plus.Add(new K() { Open = open, Close = close });
                }
                else if(open < close)
                {
                    minus.Add(new K() { Open = open, Close = close });
                }
            }

            //open と close の数がずれてる場合
            if (plus.Sum(k => k.Open - k.Close) != minus.Sum(k => k.Close - k.Open))
            {
                Console.WriteLine("No");
                return;
            }

            var comp = Comparer<K>.Create((a, b) => a.Close.CompareTo(b.Close));
            plus.Sort(comp);

            var o = 0;

            foreach (var k in plus)
            {
                if(k.Close > o)
                {
                    Console.WriteLine("No");
                    return;
                }

                o += k.Open - k.Close;
            }

            o = 0;

            comp = Comparer<K>.Create((a, b) => a.Open.CompareTo(b.Open));
            minus.Sort(comp);

            foreach (var k in minus)
            {
                if (k.Open > o)
                {
                    Console.WriteLine("No");
                    return;
                }

                o += k.Close - k.Open;
            }


            Console.WriteLine("Yes");
        }

        struct K
        {
            public int Open;
            public int Close;
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}