N = gets.to_i
D = gets.chomp.split(" ").map(&:to_i)

def factorial(n)
  return 1 if n.zero?

  (1..n).inject(:*)
end

ans = 1
sD = D.sort
if D[0] != 0 then
  ans = 0
elsif sD.last != sD.uniq.length - 1  then
  ans = 0
elsif  sD.count(0) > 1 then
  ans = 0
else
  for i in 1..sD.uniq.length - 1 do
    ans *= sD.count(i-1) ** sD.count(i)
  end
end

p ans.modulo(998244353)
