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 Go (1.14.1) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type hp struct{ sort.IntSlice }

func (h hp) Less(i, j int) bool  { return h.IntSlice[i] > h.IntSlice[j] } // 最大堆
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h *hp) pop() int           { return heap.Pop(h).(int) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ r, l int }

	var n int
	Fscan(in, &n)
	a := make([][]byte, n)
	cntL,cntR:=0,0
	checks:=[]pair{}
	for i := range a {
		Fscan(in, &a[i])
		l :=0
		rl := []byte{}
		for _, b := range a[i] {
			if b == '(' {
				l++
			} else {
				if l ==0 {
					rl = append(rl, b)
				} else {
					l--
				}
			}
		}

		if len(rl) == 0 {
			if l > 0 {
				cntL+= l
			}
		} else if l ==0 {
			cntR+=len(rl)
		} else {
			//for ; l >0; l-- {
			//	rl = append(rl, '(')
			//}
			checks = append(checks, pair{len(rl), l})
		}
	}
	sort.Slice(checks, func(i, j int) bool { a, b := checks[i], checks[j]; return a.r < b.r || a.r == b.r && a.l > b.l })
h:= &hp{}
	i:=0
	for ;i<len(checks); {
		if checks[i].r > cntL {
			Fprintln(out, "No")
			return
		}
		for ;i<len(checks);i++ {
			if checks[i].r <= cntL {
				h.push(checks[i].l-checks[i].r)
			} else {
				break
			}
		}
		for !h.empty() && h.top()>0 {
			cntL+=h.pop()
		}
	}
	for !h.empty() {
		cntL+=h.pop()
	}

	//for _, p := range checks {
	//	r,l := p.r,p.l
	//	if r > cntL {
	//
	//	}
	//	cntL+=l-r
	//}

	if cntL == cntR {
		Fprintln(out, "Yes")
	} else {
		Fprintln(out, "No")
	}

}

func main() { run(os.Stdin, os.Stdout) }