def ppow(x, n)
    return 1 if n == 0
    a = 1
    n.times do
        a = (a * x) % 998244353
    end
    return a
end

n = gets.to_i
d = gets.split.map(&:to_i)

if d[0] != 0
    puts "0"
    return
end

c = Array.new(n, 0)
for i in 0...n
    c[d[i]] += 1
end

for i in 1...n-1
    if c[i] == 0 && c[i+1] > 0
        puts "0"
        return
    end
end

ans = 1
for i in 1...n
    x = c[i-1]
    y = ppow(x, c[i])
    ans = (ans * y) % 998244353
end

puts ans
