import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 998_244_353, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread!ulong();
    auto d = aryread!ulong();
    auto count = new ulong[](n - 1);
    auto dist = new ulong[](n - 1);
    foreach (e; d)
        count[e]++;
    if (d[0] != 0 || count[0] > 1)
    {
        writeln(0);
        return;
    }
    dist[0] = 1;
    foreach (i; iota(1, n - 1))
    {
        dist[i] = dist[i - 1] * powmod(count[i - 1], count[i], MOD);
        dist[i] %= MOD;
    }
    // dist.writeln();
    dist[$ - 1].writeln();
}

auto powmod(ulong x, ulong n, ulong m)
{
    ulong ret = 1;
    while(n > 0)
    {
        ret *= x;
        ret %= m;
        n--;
    }
    return ret % m;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
