[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let MOD = 998244353L

let pow x y =
    let rec aux k x y =
        if y = 0L then
            k
        else
            aux ((k * x) % MOD) x (y - 1L)
    aux 1L x y

[<EntryPoint>]
let main _ =
    let N = read int64
    let DS = reads int64

    let bs =
        List.groupBy id DS
        |> List.map (fun (x, y) -> (x, int64 <| List.length y))
        |> List.sortBy fst

    let cs = List.pairwise bs

    // eprintfn "*%A" cs

    let rec solve acc = function
        | [] -> acc % MOD
        | ((x, xlen), (y, ylen)) :: xs ->
            if y - x <> 1L then
                0L
            else
                let d = pow xlen ylen
                solve (acc * d) xs

    if List.head bs = (0L, 1L) then
        solve 1L cs
    else
        0L
    |> printfn "%i"

    0