local mod = 998244353
local function bmul(x, y) return (x * y) % mod end
local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = pow // 2
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = 0
end
local tmp = true
local maxlen = 0
for i = 1, n do
  local a = io.read("*n")
  if i == 1 then
    tmp = a == 0
  end
  maxlen = math.max(maxlen, a + 1)
  t[a + 1] = t[a + 1] + 1
end
if not tmp then print(0) os.exit() end
for i = 1, maxlen do
  if t[i] == 0 then
    print(0)
    os.exit()
  end
end
if t[1] ~= 1 then
  print(0)
  os.exit()
end
local ret = 1
for i = 2, maxlen do
  ret = bmul(ret, modpow(t[i - 1], t[i]))
end
print(ret)
