module simple;import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, core.stdc.string;

immutable long MOD = 998244353;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    if (A[0] != 0 || A.map!(a => a == 0).sum >= 2) {
        writeln(0);
        return;
    }

    auto D = new long[](N+10);
    foreach (a; A) D[a] += 1;

    foreach (i; 1..N) {
        if (D[i-1] > 0 && D[i+1] > 0 && D[i] == 0) {
            writeln(0);
            return;
        }
    }

    long ans = 1;
    foreach (i; 1..N) {
        if (D[i] == 0) break;
        ans = ans * powmod(D[i-1], D[i], MOD) % MOD;
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}
