{-# LANGUAGE BangPatterns               #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE UndecidableInstances       #-}
import           Control.Monad.State
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Vector.Algorithms.Heap as V
import qualified Data.Vector.Unboxing        as VU

main :: IO ()
main = do
  n <- readLn @Int
  av <- readLnAsUVecWith unconsInt n

  av' <- VU.thaw av
  V.sortBy (flip compare) av'
  avec <- VU.freeze av'

  print $ case solve n avec of
    Just x  -> x
    Nothing -> 0


solve :: Int -> VU.Vector Int -> Maybe IntMod
solve = go 1
  where go :: IntMod -> Int -> VU.Vector Int -> Maybe IntMod
        go a 0 _ = Just a
        go a 1 w = if w VU.! 0 == 0 then Just a else Nothing
        go a m w = let fs = VU.take 2 w
                   in if fs VU.! 0 == m-1 && fs VU.! 1 == m-1
                      then go (a*2) (m-2) (VU.drop 2 w)
                      else Nothing


modulus :: Int
-- modulus = 10^9 + 7
modulus = 1000000007

newtype IntMod = IntMod Int deriving Eq deriving newtype VU.Unboxable

fromIntegralIntIntMod :: Int -> IntMod
fromIntegralIntIntMod n = IntMod (n `mod` modulus)
{-# RULES
"fromIntegral/Int->IntMod"
    fromIntegral = fromIntegralIntIntMod
#-}

instance Show IntMod where
  show (IntMod x) = show x

instance Num IntMod where
  IntMod x + IntMod y = IntMod ((x + y) `mod` modulus)
  IntMod x - IntMod y = IntMod ((x - y) `mod` modulus)
  IntMod x * IntMod y = IntMod ((x * y) `mod` modulus)
  fromInteger n = IntMod (fromInteger (n `mod` fromIntegral modulus))
  abs = undefined
  signum = undefined

unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

readLnAsUVecWith :: VU.Unboxable a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector a)
readLnAsUVecWith !st !n = VU.unfoldrN n (runStateT st) <$> BS.getLine
