from collections import Counter

from itertools import tee



N = int(eval(input()))

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

R = 998244353





def pairwise(iterable):

    a, b = tee(iterable)

    next(b, None)

    return list(zip(a, b))





def is_leap(distance):

    cc = Counter(distance)

    for x, y in pairwise(sorted(cc.keys())):

        if y - x > 1:

            return True

    else:

        return False





if D[0] > 0:

    """頂点1が根ではない"""

    print((0))

elif not all(D[1:]):

    """連結グラフではない"""

    print((0))

elif is_leap(D):

    print((0))

else:

    ans = 1

    c = Counter(D[1:])

    edges = [t[1] for t in sorted(c.items())]

    for d, e in pairwise(edges):

        ans *= pow(d, e)

    print((ans % R))

from collections import Counter

from itertools import tee



N = int(eval(input()))

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

R = 998244353





def pairwise(iterable):

    a, b = tee(iterable)

    next(b, None)

    return list(zip(a, b))





def is_leap(distance):

    cc = Counter(distance)

    for x, y in pairwise(sorted(cc.keys())):

        if y - x > 1:

            return True

    else:

        return False





if D[0] > 0:

    """頂点1が根ではない"""

    print((0))

elif not all(D[1:]):

    """連結グラフではない"""

    print((0))

elif is_leap(D):

    """連結グラフではない"""

    print((0))

else:

    ans = 1

    c = Counter(D[1:])

    edges = [t[1] for t in sorted(c.items())]

    for d, e in pairwise(edges):

        ans *= pow(d, e)

        ans = ans % R

    print((ans % R))

from collections import Counter
from itertools import tee

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


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return list(zip(a, b))


def is_leap(distance):
    cc = Counter(distance)
    for x, y in pairwise(sorted(cc.keys())):
        if y - x > 1:
            return True
    else:
        return False


if D[0] > 0:
    """頂点1が根ではない"""
    print((0))
elif not all(D[1:]):
    """連結グラフではない"""
    print((0))
elif is_leap(D):
    print((0))
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e)
    print((ans % R))

from collections import Counter
from itertools import tee

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


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return list(zip(a, b))


def is_leap(distance):
    cc = Counter(distance)
    for x, y in pairwise(sorted(cc.keys())):
        if y - x > 1:
            return True
    else:
        return False


if D[0] > 0:
    """頂点1が根ではない"""
    print((0))
elif not all(D[1:]):
    """連結グラフではない"""
    print((0))
elif is_leap(D):
    """連結グラフではない"""
    print((0))
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e)
        ans = ans % R
    print((ans % R))

+    """連結グラフではない""" +        ans = ans % R