import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    auto arr = readln.chomp.split.map!(to!int).array;
    
    if (arr[0] != 0) {
        writeln(0);
        return;
    }
    
    arr = arr.dropOne.array;
    
    arr.sort();
    
    immutable int MD = 998244353;
    int ans = 1, prevk = 0, prevv = 1, curk = 1, curv = 0;
    foreach (e; arr) {
        if (e > curk) {
            if (e > curk + 1) {
                writeln(0);
                return;
            }
            
            prevk = curk;
            prevv = curv;
            
            curk = e;
            curv = 0;
        }
        
        ++curv;
        
        debug { [prevk, prevv, curk, curv].map!(to!string).join(" ").writeln; }
        
        ans = (ans * prevv) % MD;
    }
    
    ans.writeln;
}