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)

use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let v: Vec<usize> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.split_whitespace().map(|x| x.parse().unwrap()).collect()
    };

    let ans =
    if is_valid(v) {
        modulo::Modulo::new(2).pow(n / 2).0
    } else {
        0
    };
    println!("{}", ans);
}

fn is_valid(v: Vec<usize>) -> bool {
    let n = v.len();
    let mut count = vec![0; n + 1];
    for x in &v {
        count[*x] += 1;
    }

    let mut expect = vec![0; n + 1];
    if n % 2 == 0 {
        let mut i = 1;
        while i <= n {
            expect[i] = 2;
            i += 2;
        }
    } else {
        expect[0] = 1;

        let mut i = 2;
        while i <= n {
            expect[i] = 2;
            i += 2;
        }
    }

    count == expect
}

fn check_val(i: usize, count: usize, n: usize) -> bool {
    if n % 2 == 0 {
        if i % 2 == 0 {
            if count != 0 {
                return false;
            }
        } else {
            if count != 2 {
                return false;
            }
        }
    } else {
        if i == 0 {
            if count != 1 {
                return false;
            }
        } else if i % 2 == 0 {
            if count != 2 {
                return false;
            }
        } else {
            if count != 0 {
                return false;
            }
        }
    }

    true
}

mod modulo {
    use std::ops::{Add, Mul, Sub};

    fn positive_rem(a: isize, b: usize) -> usize {
        let b = b as isize;
        let mut value = a % b;
        if value < 0 {
            value += b;
        }
        // TODO: TryFrom
        value as usize
    }

    /// Return (x, y) s.t. ax + by = d where d = gcd(a, b)
    fn ext_gcd(a: usize, b: usize) -> (isize, isize) {
        if b == 0 {
            return (1, 0);
        }

        let q = (a / b) as isize;
        let r = a % b;
        let (x1, y1) = ext_gcd(b, r);
        (y1, x1 - q * y1)
    }

    #[derive(Debug, Copy, Clone)]
    pub struct Modulo(pub usize);

    const MODULO: usize = 1_000_000_007;

    impl Modulo {
        pub fn new(n: usize) -> Modulo {
            // TODO: use TryFrom
            Modulo(n % MODULO)
        }

        pub fn from_isize(n: isize) -> Modulo {
            // TODO: use TryFrom
            Modulo(positive_rem(n, MODULO as usize))
        }

        pub fn pow(self, p: usize) -> Modulo {
            if self == Modulo(0) {
                return Modulo(0);
            }
            if p == 0 {
                return Modulo(1);
            }

            if p % 2 == 0 {
                let half = self.pow(p / 2);
                half * half
            } else {
                self.pow(p - 1) * self
            }
        }

        // when MODULO is prime
        pub fn inv(self) -> Modulo {
            let (x, _) = ext_gcd(self.0 as usize, MODULO as usize);
            Modulo::from_isize(x)
        }

        // when MODULO is prime
        pub fn binom_coef(n: isize, k: isize) -> Modulo {
            let mut ret = Modulo::from_isize(1);
            for i in 1..(k + 1) {
                ret = ret * Modulo::from_isize(n - i + 1) * Modulo::from_isize(i).inv();
            }
            ret
        }
    }

    impl Add for Modulo {
        type Output = Modulo;

        fn add(self, other: Modulo) -> Modulo {
            Modulo((self.0 + other.0) % MODULO)
        }
    }

    impl Sub for Modulo {
        type Output = Modulo;

        fn sub(self, other: Modulo) -> Modulo {
            Modulo(positive_rem(
                self.0 as isize - other.0 as isize,
                MODULO as usize,
            ))
        }
    }

    impl Mul for Modulo {
        type Output = Modulo;

        fn mul(self, other: Modulo) -> Modulo {
            Modulo((self.0 * other.0) % MODULO)
        }
    }

    impl PartialEq for Modulo {
        fn eq(&self, &other: &Self) -> bool {
            self.0 == other.0
        }
    }

    impl Eq for Modulo {}
}