from collections import Counter

import sys

MOD = 998244353





def main():

    n, *d =  list(map(int, sys.stdin.buffer.read().split()))

    D = Counter(d)

    if D[0] != 1:

        print((0))

    else:

        ans = 1

        for i in d[1:]:

            ans = ans*D[i-1]%MOD

        print((ans % MOD))





if __name__ == '__main__':

    main()

from collections import Counter

import sys

MOD = 998244353





def main():

    n, *d = list(map(int, sys.stdin.buffer.read().split()))

    e = [0]*n

    for i in d:

        e[i] += 1

    ans = e[0]

    for i in d[1:]:

        ans *= e[i-1]

        ans %= MOD

    print(ans)





if __name__ == '__main__':

    main()

from collections import Counter
import sys

MOD = 998244353


def main():
    n, *d = list(map(int, sys.stdin.buffer.read().split()))
    D = Counter(d)
    if D[0] != 1:
        print((0))
    else:
        ans = 1
        for i in d[1:]:
            ans = ans * D[i - 1] % MOD
        print((ans % MOD))


if __name__ == "__main__":
    main()

from collections import Counter
import sys

MOD = 998244353


def main():
    n, *d = list(map(int, sys.stdin.buffer.read().split()))
    e = [0] * n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans *= e[i - 1]
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

-    D = Counter(d) -    if D[0] != 1: -        print((0)) -    else: -        ans = 1 -        for i in d[1:]: -            ans = ans * D[i - 1] % MOD -        print((ans % MOD)) +    e = [0] * n +    for i in d: +        e[i] += 1 +    ans = e[0] +    for i in d[1:]: +        ans *= e[i - 1] +        ans %= MOD +    print(ans)