void main() {
    int n = readln.chomp.to!int;
    long[] d = readln.split.to!(long[]);
    long mod = 998244353;
    long ans;
    if (d[0] == 0) {
        long[] a = d[1..$];
        a.sort!"a < b";
        if (a[0] == 1) {
            ans = 1;
            auto g = a.group.array;
            long b = 1;
            long c;
            foreach (x; g) {
                if (x[0] == 1) {
                    c = x[1].to!long;
                } else if (x[0] == b + 1) {
                    ans = ans * (c ^^ x[1].to!long) % mod;
                    ++b;
                    c = x[1].to!long;
                } else {
                    ans = 0;
                    break;
                }
            }
        }
    }
    ans.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;