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 Rust (1.42.0) (judge verdict: Wrong Answer)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competitive::prelude::*;

fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    }

    let t = s
        .into_iter()
        .map(|s| {
            let mut low = 0;
            let mut cur = 0;
            for c in s {
                if c == '(' {
                    cur += 1;
                } else {
                    cur -= 1;
                }

                low = min(low, cur);
            }
            (low, cur)
        })
        .collect_vec();

    let pos = t
        .iter()
        .filter(|r| r.1 >= 0)
        .sorted_by_key(|r| -r.0)
        .collect_vec();
    let neg = t
        .iter()
        .filter(|r| r.1 < 0)
        .sorted_by_key(|r| (-r.1, r.0))
        .collect_vec();

    let mut cur = 0;

    for &(low, inc) in pos {
        if cur + low < 0 {
            echo!("No");
            return;
        }
        cur += inc;
    }

    for &(low, inc) in neg {
        if cur + low < 0 {
            echo!("No");
            return;
        }
        cur += inc;
    }

    echo!(yn(cur == 0));
}
*/

fn main() {
    let exe = "/tmp/binB3F571CE";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";