MOD = 998244353
def modpow(x,n)
  ret = 1
  while n > 0
    ret = ret*x % MOD if n&1 == 1
    x = x*x % MOD
    n >>= 1
  end
  return ret
end

n = gets.to_i
d = gets.split.map(&:to_i)
if d[0] != 0
  p 0
  exit
end

cnt = [0]*n
d.each do |v|
  if v >= n
    p 0
    exit
  end
  cnt[v] += 1
end

if cnt[0] > 1
  p 0
  exit
end

ans = 1
prev = 1
sum = 0
cnt.each do |v|
  sum += v
  ans *= modpow(prev,v)
  ans %= MOD
  prev = v
  if v == 0
    if sum != n
      p 0
      exit
    end
    break
  end
end

p ans