from collections import Counter

N = int(eval(input()))

D = list(map(int, input().split()))

MOD = 998244353



def calc():

    if D[0] != 0:

        return 0

    if sum(D) < N-1:

        return 0

    

    c = Counter(D)

    ret = 1

    tmpkey = 0

    tmpvalue = 0

    for key in sorted(c.keys()):

        if key - tmpkey >= 2:

            return 0

        if key == 0:

            if c[key] >= 2:

                return 0

        else:

            ret *= (tmpvalue ** c[key]) % MOD

            ret %= MOD

        tmpkey = key

        tmpvalue = c[key]

    return ret



print((calc()))

from collections import Counter

N = int(eval(input()))

D = list(map(int, input().split()))

MOD = 998244353



# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく

count = [0] * N

for d in D:

    count[d] += 1



def calc():

    if D[0] != 0:

        return 0

    ret = 1

    for i in range(N):

        if i == 0:

            if count[i] >= 2:

                return 0

        else:

            ret *= (count[i-1] ** count[i]) % MOD

            ret %= MOD

    return ret



print((calc()))

from collections import Counter

N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353


def calc():
    if D[0] != 0:
        return 0
    if sum(D) < N - 1:
        return 0
    c = Counter(D)
    ret = 1
    tmpkey = 0
    tmpvalue = 0
    for key in sorted(c.keys()):
        if key - tmpkey >= 2:
            return 0
        if key == 0:
            if c[key] >= 2:
                return 0
        else:
            ret *= (tmpvalue ** c[key]) % MOD
            ret %= MOD
        tmpkey = key
        tmpvalue = c[key]
    return ret


print((calc()))

from collections import Counter

N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく
count = [0] * N
for d in D:
    count[d] += 1


def calc():
    if D[0] != 0:
        return 0
    ret = 1
    for i in range(N):
        if i == 0:
            if count[i] >= 2:
                return 0
        else:
            ret *= (count[i - 1] ** count[i]) % MOD
            ret %= MOD
    return ret


print((calc()))

+# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく +count = [0] * N +for d in D: +    count[d] += 1 -    if sum(D) < N - 1: -        return 0 -    c = Counter(D) -    tmpkey = 0 -    tmpvalue = 0 -    for key in sorted(c.keys()): -        if key - tmpkey >= 2: -            return 0 -        if key == 0: -            if c[key] >= 2: +    for i in range(N): +        if i == 0: +            if count[i] >= 2: -            ret *= (tmpvalue ** c[key]) % MOD +            ret *= (count[i - 1] ** count[i]) % MOD -        tmpkey = key -        tmpvalue = c[key]