CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter

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

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in range(1, m+1):
    ans *= c[i-1]**c[i] % mod
    ans %= mod
  print(ans)
else:
  print((0))

# Optimized solution
from collections import Counter

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

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in range(1, m+1):
    ans *= c[i-1]**c[i]
    ans %= mod
  print(ans)
else:
  print((0))
# Original solution
from collections import Counter

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

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in range(1, m+1):
    ans *= c[i-1]**c[i]
    ans %= mod
  print(ans)
else:
  print((0))

# Optimized solution
from collections import Counter

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

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in D[1:]:
    ans *= c[i-1]
    ans %= mod
  print(ans)
else:
  print((0))
# Original solution
# coding: utf-8
N = int(eval(input()))
D = list(map(int, input().split()))
l = [0] * N
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print((0))
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

# Optimized solution
# coding: utf-8
N = int(eval(input()))
D = list(map(int, input().split()))
l = [0] * N
top = max(D)
mod = 998244353
for i in range(N):
    l[D[i]] += 1
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print((0))
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
print(ans)
# Original solution
from collections import Counter

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

# 条件をみたす木が存在するには D1 = 0 が必要
if D[0] != 0:
  print((0))
  exit()
# 0 == 1
ctr = Counter(D)
if ctr[0] != 1:
  print((0))
  exit()
  
ans = 1
for i in range(len(ctr)-1):
  ans *= pow(ctr[i], ctr[i+1], MOD)
  ans %= MOD
print(ans)  

# Optimized solution

from collections import Counter
def resolve():
    MOD = 998244353
    N = int(eval(input()))
    D = list(map(int, input().split()))

    if D[0] != 0:
        print((0))
        return

    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print((0))
        return

    ans = 1
    for i in range(1, max(D) + 1):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()
# Original solution

from collections import Counter
def resolve():
    MOD = 998244353
    N = int(eval(input()))
    D = list(map(int, input().split()))

    if D[0] != 0:
        print((0))
        return

    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print((0))
        return

    ans = 1
    for i in range(1, max(D) + 1):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()


# Optimized solution

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

    if D[0] != 0:
        print((0))
        return

    CNT = [0] * N
    for i in D:
        CNT[i] += 1

    if CNT[0] > 1:
        print((0))
        return

    ans = 1
    for i in range(1, N):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()
# Original solution
#b
n=int(eval(input()))
d=[int(i) for i in input().split()]

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or set(d)!=set(range(len(set(d)))) or 0 in d[1:]:
    print((0))
else:
    for i in range(1,len(c)):
        ans = (ans* c[i-1]**c[i]) %m
    print(ans)

# Optimized solution

n=int(eval(input()))
d=list(map(int,input().split()))

from collections import Counter
c=Counter(d)

mod=998244353
ans=1
key=set(c.keys())
if d[0]==0 and c[0]==1 and set(range(len(key))) == key:
    for i in range(len(key)):
        #print(i,c[i],c[i+1],c[i]**c[i+1])
        ans=ans*c[i]**c[i+1] %mod
else:
    ans=0
print(ans)
# Original solution
import sys
read = lambda: sys.stdin.readline().rstrip()

def counting_tree(N, D):
    import collections
    tot = 1

    cnt = collections.Counter(D)
    """
    cnt = [0]*N
    for i in D:
        cnt[i]+=1
    """

    for i in D[1:]:
        tot = tot * cnt[i-1]%998244353

    return tot if D[0]==0 else 0

def main():
    
    N0 = int(read())
    D0 = tuple(map(int, read().split()))

    res = counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
read = lambda: sys.stdin.readline().rstrip()

class Solution(object):
    def counting_tree(self, N, D):
        #import collections
        tot = 1

        #cnt = collections.Counter(D)

        cnt = [0]*N
        for i in D:
            cnt[i]+=1

        for i in D[1:]:
            tot = tot * cnt[i-1]%998244353

        return tot if D[0]==0 else 0

def main():
    
    N0 = int(read())
    D0 = tuple(map(int, read().split()))

    res = Solution().counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()
# Original solution
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()


# Optimized solution
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()
# Original solution
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()


# Optimized solution
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()
# Original solution
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()


# Optimized solution
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 = ans*e[i-1] % MOD
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
from collections import Counter

n = int(eval(input()))
d = list(map(int, input().split()))

count = Counter(d)

if d[0] != 0:
    print((0))
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print((0))
    
else:
    ans = 1
    tmp = 1
    len_d = len(d)
    for i in range(1, len_d+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print((ans%998244353))



# Optimized solution
from collections import Counter

n = int(eval(input()))
d = list(map(int, input().split()))

count = Counter(d)

if d[0] != 0:
    print((0))
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print((0))
    
else:
    ans = 1
    tmp = 1
    max_d = max(d)
    for i in range(1, max_d+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print((ans%998244353))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
if a[0] > 0 or a.count(0) > 1:
  print((0))
  exit()
  
a = sorted(a)
dp = [0]*(n+1)
dp[0] = 1
count_list = [0]*n
count_list[0] = 1
for i in range(1, n):
  num = a[i]
  count_list[num] += 1
  dp[a[i]] = dp[num-1] * count_list[num-1] ** count_list[num] % 998244353
print((dp[a[n-1]]))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
if a[0] > 0 or a.count(0) > 1:
  print((0))
  exit()
  
a = sorted(a)
dp = [0]*(n+1)
dp[0] = 1
count_list = [0]*n
count_list[0] = 1
for i in range(1, n):
  count_list[a[i]] += 1
for i in range(1, a[n-1]+1):
  dp[i] = dp[i-1] * count_list[i-1] ** count_list[i] % 998244353
print((dp[a[n-1]]))
# Original solution
n = int(eval(input()))
d = list(map(int, input().split()))

a = [0] * n
for i in range(n):
    a[d[i]] += 1

if a[0] == 1 and d[0] == 0:
    ans = 1
    for i in range(1, n):
        ans *= a[i-1]**a[i]

    print((ans % 998244353))
else:
    print((0))

# Optimized solution
n = int(eval(input()))
d = list(map(int, input().split()))

a = [0] * n
for i in range(n):
    a[d[i]] += 1

if a[0] == 1 and d[0] == 0:
    ans = 1
    for i in range(1, n):
        ans *= a[i-1]**a[i]
        ans %= 998244353

    print(ans)
else:
    print((0))
# Original solution
_,d=open(0)
*d,=list(map(int,d.split()))
e=[0]*10**5
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print((a%998244353))

# Optimized solution
_,d=open(0)
*d,=list(map(int,d.split()))
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print((a%998244353))
# Original solution
def main():
  n,*d=list(map(int,open(0).read().split()))
  e=[0]*n
  for i in d:e[i]+=1
  a=1if d[0]<1else 0
  for i in d[1:]:a=a*e[i-1]%998244353
  print(a)
main()

# Optimized solution
def main():
  import sys
  n,*d=list(map(int,sys.stdin.buffer.read().split()))
  e=[0]*n
  for i in d:e[i]+=1
  a=1if d[0]<1else 0
  for i in d[1:]:a=a*e[i-1]%998244353
  print(a)
main()
# Original solution
import sys


def answerA():
    input = sys.stdin.readline
    N = int(eval(input()))

    print(((N-1) // 2))


def answer():
    input = sys.stdin.readline
    N = int(eval(input()))
    distances = list(map(int, input().split()))

    maximum = max(distances)
    counts = []

    for d in range(maximum + 1):
        counts.append(distances.count(d))

    result = 1
    mod = 998244353

    if 0 in counts:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        for d in distances[1:]:
            result *= counts[d-1]
            result %= mod

    print(result)


if __name__ == '__main__':
    answer()


# Optimized solution
def answer():
    N = int(eval(input()))
    distances = list(map(int, input().split()))

    result = 1
    mod = 998244353

    if distances[0] != 0:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        distances.sort()
        maximum = distances[-1]
        counts = [0] * (maximum + 1)
        counts[0] = 1
        for d in distances[1:]:
            counts[d] += 1
            result *= counts[d-1]
            result %= mod

    print(result)


if __name__ == '__main__':
    answer()
# Original solution
a = int(eval(input()))
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if dp[0] != 1 and l[0]!=0:
    print((0))
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]

print((res%MOD))

# Optimized solution
a = int(eval(input()))
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if dp[0] != 1 and l[0]!=0:
    print((0))
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]
    res%=MOD

print(res)
# Original solution
a = int(eval(input()))
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if  l[0]!=0:
    print((0))
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]
    res%=MOD

print((res%MOD))

# Optimized solution
a = int(eval(input()))
l = list(map(int,input().split()))
d = [0]*a
for i in l:
    d[i]+=1
r =1
if  l[0]!=0:
    print((0))
    exit()
for i in l[1:]:
    r=r*d[i-1]%998244353
print(r)
# Original solution
n=int(eval(input()))
d=list(map(int,input().split()))
q=[]
#from collections import Counter
#q=Counter(d)

for i in range(max(d)+1):
    q.append(d.count(i))

if q[0]!=1 or d[0]!=0:
    print((0))
    exit()

ans=1
for i in range(1,max(d)+1):
    ans*=q[i-1]**q[i]
    if ans == 0:
        break
print((ans%998244353))

# Optimized solution
n=int(eval(input()))
d=list(map(int,input().split()))
q=[0]*(max(d)+1)
#from collections import Counter
#q=Counter(d)


for i in range(len(d)):
    q[d[i]]+=1
    
if q[0]!=1 or d[0]!=0:
    print((0))
    exit()

ans=1
for i in range(1,max(d)+1):
    ans*=q[i-1]**q[i]
    if ans == 0:
        break
print((ans%998244353))
# Original solution
import collections
import sys

n = int(eval(input()))
d = list(map(int, input().split()))

cnt = collections.Counter(d)

if d[0]!=0:
    print((0))
    sys.exit(0)

if cnt[0]!=1:
    print((0))
    sys.exit(0)    
    
p = 1

for i in range(1,max(d)+1):
    if cnt[i] == 0:
        print((0))
        sys.exit(0)  
    else:
        p = (p * pow(cnt[i-1], cnt[i], 998244353))%998244353

print(p)

# Optimized solution
import collections
import sys

n = int(eval(input()))
d = list(map(int, input().split()))

cnt = collections.Counter(d)

if d[0]!=0:
    print((0))
    sys.exit(0)

if cnt[0]!=1:
    print((0))
    sys.exit(0)    
    
p = 1

for i in range(1,max(d)+1):
    p = (p * pow(cnt[i-1], cnt[i], 998244353))%998244353

print(p)
# Original solution
def main():

    N = eval(input())
    D = list(map(int,input().split()))
    M = max(D)
    countlist=[0] * (M + 1)
    ans=1

    for i in D:
        countlist[i]+=1

    if countlist[0]!=1 :
        ans = 0
    else :
        if D[0]!=0 :
            ans = 0
        else:
            for i in range(2,M+1):
                ans *= countlist[i-1]**countlist[i]

    print((ans%998244353)) 

if __name__ == "__main__":
    main()

# Optimized solution
def main():

    N = eval(input())
    D = list(map(int,input().split()))
    M = max(D)
    countlist=[0] * (M + 1)
    ans=1

    for i in D:
        countlist[i]+=1

    if countlist[0]!=1 :
        ans = 0
    else :
        if D[0]!=0 :
            ans = 0
        else:
            for i in range(2,M+1):
                ans = ans * (countlist[i-1]**countlist[i]) % 998244353

    print(ans) 

if __name__ == "__main__":
    main()
# Original solution
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()))


# Optimized solution
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()))
# Original solution
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(N + 1):
        ans *= p[i] ** p[i + 1]
        ans %= MOD

    print((ans % MOD))

else:
    print((0))


# Optimized solution
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= p[i] ** p[i + 1]
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print((0))
# Original solution
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    cn=[0]*N
    for i in range(N):
        cn[D[i]]+=1

    if D[0]!=0:
        print((0))
    else:
        answer=1
        bak=cn[0]
        kyo=1
        hen=1
        while True:
            if kyo >= N:
                while True:
                    pass
            cnt=cn[kyo]
            hen+=cnt
            if cnt==0:
                break
            answer=answer*baai(bak, cnt)%MOD
            bak=cnt
            kyo+=1
        if hen==N:
            print((answer%MOD))
        else:
            print((0))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    cn=[0]*(N + 1)
    for i in range(N):
        cn[D[i]]+=1

    if D[0]!=0:
        print((0))
    else:
        answer=1
        bak=cn[0]
        kyo=1
        hen=1
        while True:
            cnt=cn[kyo]
            hen+=cnt
            if cnt==0:
                break
            answer=answer*baai(bak, cnt)%MOD
            bak=cnt
            kyo+=1
        if hen==N:
            print((answer%MOD))
        else:
            print((0))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()
# Original solution
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if c[0] != 1:
        return 0

    for i in range(max(c) + 1):
        if i not in c:
            return 0

    c = list(c.items())
    c.sort()

    prev = 1
    ans = 1
    mod = 998244353

    for _, i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


n = int(eval(input()))
arr = list(map(int, input().split()))

print((solve(n, arr)))

# Optimized solution
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if c[0] != 1:
        return 0

    for i in range(max(c) + 1):
        if i not in c:
            return 0

    c = list(c.items())
    c.sort()

    prev = 1
    ans = 1
    mod = 998244353

    for _, i in c[1:]:
        ans *= prev**i % mod
        ans %= mod
        prev = i

    return ans


n = int(eval(input()))
arr = list(map(int, input().split()))

print((solve(n, arr)))
# Original solution
mod = 998244353
n = int(eval(input()))
d = list(map(int, input().split()))
if d[0] != 0:
    print((0))
    exit()
lis = []
for i in range(n):
    lis.append(d.count(i))
if lis[0] != 1:
    print((0))
    exit()
ans = 1
for i in range(1, n):
    ans *= pow(lis[i-1], lis[i], mod)
    ans %= mod
print(ans)

# Optimized solution
mod = 998244353
n = int(eval(input()))
d = list(map(int, input().split()))
if d[0] != 0:
    print((0))
    exit()
lis = [0] * n
for i in d:
    lis[i] += 1
if lis[0] != 1:
    print((0))
    exit()
ans = 1
for i in range(1, n):
    ans *= pow(lis[i-1], lis[i], mod)
    ans %= mod
print(ans)
# Original solution
from collections import Counter
mod=998244353
n=int(eval(input()))
D=list(map(int,input().split()))
Count=Counter(D)
if Count[0]!=1 or D[0]!=0:print((0));exit()
ans=1
for i in range(1,max(Count)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)

# Optimized solution
from collections import Counter
mod=998244353
n=int(eval(input()))
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 or Count[0]!=1:print((0));exit()
ans=1
for i in range(1,max(Count)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)
# Original solution
MOD = 998244353

n = int(eval(input()))
distances = list([int(x) for x in input().split()])

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in list(dist_list.keys()):
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        ans *= (smaller**bigger)
        ans = ans % MOD
        
print(ans)

# Optimized solution
MOD = 998244353

n = int(eval(input()))
distances = list([int(x) for x in input().split()])

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in list(dist_list.keys()):
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    pre_v = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            pre_v = v
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        if v==0 and smaller > 1:
            ans = 0

        if v == pre_v - 1:
            ans *= (smaller**bigger)
            ans = ans % MOD
            pre_v = v
        else:
            ans = 0
        
print(ans)
# Original solution
n = int(eval(input()))
d = list(map(int, input().split()))

x = []
for i in range(max(d)+1):
	x.append(d.count(i))
ans = 1
if d[0] == 0 and x[0] == 1:
	for i in range(1, len(x)-1):
		ans = ans * (x[i]**x[i+1])
else:
	ans = 0

print((ans%998244353))

# Optimized solution
n = int(eval(input()))
d = list(map(int, input().split()))

dd = sorted(d)
c = []
j = 0
for i in range(max(d)+1):
	tmp = 0
	while dd[j] == i:
		tmp += 1
		j += 1
		if j == n:
			break
	c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1 and c.count(0) == 0:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print((ans%998244353))