import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ds <- getIntList
    print $ solve ds

solve [] = 0
solve (d:ds)
    | d /= 0 || map head ds' /= [1..length ds'] = 0
    | otherwise = productMod $ zipWith powerMod ds'' (tail ds'')
    where ds' = group $ sort ds
          ds'' = map length ds'

moduloN :: Int
moduloN = 998244353
modN = flip mod moduloN

mulMod x y = modN $ x * y
productMod xs = foldl' mulMod 1 xs

powerMod x 0 = 1
powerMod x y
    | even y = mulMod t t
    | otherwise = mulMod x $ mulMod t t
    where
        t = powerMod x $ div y 2