n = gets.to_i
ds = gets.split.map(&:to_i)
mod = 998244353
cnt = Array.new(ds.max+1, 0)
(0..n-1).each do |i|
  if (i == 0 && ds[i] != 0) || (i != 0 && ds[i] == 0)
    puts 0
    exit
  end
  cnt[ds[i]] += 1
end
cnt.shift
ans = 1
(0..cnt.length-2).each do |i|
  ans = ans * (cnt[i] ** cnt[i + 1])
end
ans %= mod
puts ans
