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)

macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _a: [usize; n]
   }
   let mut a = _a;
   let mut flag = true;
   a.sort();
   let mut now = 0;
   if n % 2 == 1 {
      if a[0] != 0 {
         flag = false;
      }
      now += 1;
   }
   while now < a.len() {
      if a[now] == a[now + 1] && a[now] == now + 1 {
         now += 2;
         continue;
      }
      flag = false;
      break;
   }
   if flag {
      println!("{}", Mint::new(2).pow(a.len() / 2).x);
   } else {
      println!("0");
   }
}

const MOD: i64 = 1000000007;
#[derive(Copy, Clone)]
pub struct Mint {
   x: i64,
}
impl Mint {
   fn new(x: i64) -> Self {
      Mint {
         x: (x % MOD + MOD) % MOD,
      }
   }
   fn pow(self, n: usize) -> Self {
      match n {
         0 => Mint::new(1),
         _ => {
            let mut a = self.pow(n >> 1);
            a *= a;
            if n & 1 == 1 {
               a *= self;
            }
            a
         }
      }
   }
   fn inv(self) -> Self { self.pow((MOD - 2) as usize) }
}
impl std::ops::Neg for Mint {
   type Output = Mint;
   fn neg(self) -> Self::Output { Self::new(-self.x) }
}
impl std::ops::AddAssign<Mint> for Mint {
   fn add_assign(&mut self, rhs: Self) {
      self.x += rhs.x;
      if self.x >= MOD {
         self.x -= MOD;
      }
   }
}
impl std::ops::AddAssign<i64> for Mint {
   fn add_assign(&mut self, rhs: i64) { *self += Mint::new(rhs); }
}
impl<T> std::ops::Add<T> for Mint
where
   Mint: std::ops::AddAssign<T>,
{
   type Output = Self;
   fn add(self, other: T) -> Self {
      let mut res = self;
      res += other;
      res
   }
}
impl std::ops::SubAssign<Mint> for Mint {
   fn sub_assign(&mut self, rhs: Self) {
      self.x += MOD - rhs.x;
      if self.x >= MOD {
         self.x -= MOD;
      }
   }
}
impl std::ops::SubAssign<i64> for Mint {
   fn sub_assign(&mut self, rhs: i64) { *self -= Mint::new(rhs); }
}
impl<T> std::ops::Sub<T> for Mint
where
   Mint: std::ops::SubAssign<T>,
{
   type Output = Self;
   fn sub(self, other: T) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl std::ops::MulAssign<Mint> for Mint {
   fn mul_assign(&mut self, rhs: Self) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl std::ops::MulAssign<i64> for Mint {
   fn mul_assign(&mut self, rhs: i64) { *self *= Mint::new(rhs); }
}
impl<T> std::ops::Mul<T> for Mint
where
   Mint: std::ops::MulAssign<T>,
{
   type Output = Self;
   fn mul(self, other: T) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl std::ops::DivAssign<Mint> for Mint {
   fn div_assign(&mut self, rhs: Self) { *self *= rhs.inv(); }
}
impl std::ops::DivAssign<i64> for Mint {
   fn div_assign(&mut self, rhs: i64) { *self *= Mint::new(rhs).inv(); }
}
impl<T> std::ops::Div<T> for Mint
where
   Mint: std::ops::DivAssign<T>,
{
   type Output = Self;
   fn div(self, other: T) -> Self {
      let mut res = self;
      res /= other;
      res
   }
}
impl<T> From<T> for Mint
where
   i64: From<T>,
{
   fn from(x: T) -> Mint { Mint::new(i64::from(x)) }
}