Problem:
Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

Any order would be inconsistent with the reports, thus the answer is 0.

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
fn main() {
    proconio::input! {
        n: usize,
        a_s: [i64; n],
    }
    let mut evens = a_s.iter().filter(|a| **a % 2 == 0).collect::<Vec<_>>();
    let mut odds = a_s.iter().filter(|a| **a % 2 == 1).collect::<Vec<_>>();
    let len = if !evens.is_empty() && !odds.is_empty() {
        println!("0");
        return;
    } else if !evens.is_empty() {
        evens.sort();
        if *evens[0] != 0 {
            println!("0");
            return;
        }
        let mut cur = 2;
        for (i, &e) in evens.iter().skip(1).enumerate() {
            if *e != cur {
                println!("0");
                return;
            }
            if i % 2 == 1 {
                cur += 2;
            }
        }
        evens.len() - 1
    } else {
        odds.sort();
        let mut cur = 1;
        for (i, &e) in odds.iter().enumerate() {
            if *e != cur {
                return;
            }
            if i % 2 == 1 {
                cur += 2;
            }
        }
        odds.len()
    };
    let mut ans = 1;
    for _ in 0..len / 2 {
        ans *= 2;
        ans %= 1_000_000_007;
    }
    println!("{}", ans);
}

// 1, 2, 3, 4, 5
// 1: (0, 4): 4
// 2: (1, 3): 2
// 3: (2, 2): 0
// 4: (3, 1): 2
// 5: (4, 0): 4

// 1, 2, 3, 4, 5, 6
// 1: (0, 5): 5
// 2: (1, 4): 3
// 3: (2, 3): 1
// 4: (3, 2): 1
// 5: (4, 1): 3
// 6: (5, 0): 5
*/

fn main() {
    let exe = "/tmp/binB28CBB73";
    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>";