#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

template <std::size_t MOD> class ModuloInteger
{
public:
    ModuloInteger(const std::size_t init)
        : value(init)
    {
    }

    using value_t = std::size_t;

    ModuloInteger operator+(const ModuloInteger value) const noexcept;
    void operator+=(const ModuloInteger value) noexcept;

    ModuloInteger operator-(const ModuloInteger value) const noexcept;
    void operator-=(const ModuloInteger value) noexcept;

    ModuloInteger operator*(const ModuloInteger value) const noexcept;
    void operator*=(const ModuloInteger value) noexcept;

    ModuloInteger operator/(const ModuloInteger value) const noexcept;
    void operator/=(const ModuloInteger value) noexcept;

    ModuloInteger operator+(const std::size_t value) const noexcept;
    void operator+=(const std::size_t value) noexcept;

    ModuloInteger operator-(const std::size_t value) const noexcept;
    void operator-=(const std::size_t value) noexcept;

    ModuloInteger operator*(const std::size_t value) const noexcept;
    void operator*=(const std::size_t value) noexcept;

    ModuloInteger operator/(const std::size_t value) const noexcept;
    void operator/=(const std::size_t value) noexcept;

    ModuloInteger inv() const noexcept;

    ModuloInteger powi(const std::size_t index) const noexcept;

    std::size_t value;
};

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::powi(const std::size_t index) const noexcept
{
    if (index == 0)
    {
        return 1;
    }
    else if (index == 1)
    {
        return *this;
    }
    else if (index % 2 == 0)
    {
        auto v = powi(index / 2);
        return v * v;
    }
    else
    {
        return powi(index - 1) * (*this);
    }
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::inv() const noexcept { return powi(MOD - 2); }

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator+(const ModuloInteger value) const noexcept
{
    return (this->value + value.value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator+=(const ModuloInteger value) noexcept
{
    this->value = (this->value + value.value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator-(const ModuloInteger value) const noexcept
{
    return (this->value + MOD - value.value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator-=(const ModuloInteger value) noexcept
{
    this->value = (this->value + MOD - value.value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator*(const ModuloInteger value) const noexcept
{
    return (this->value * value.value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator*=(const ModuloInteger value) noexcept
{
    this->value = (this->value * value.value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator/(const ModuloInteger value) const noexcept
{
    return (this->value * value.inv().value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator/=(const ModuloInteger value) noexcept
{
    this->value = (this->value * value.inv().value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator+(const std::size_t value) const noexcept
{
    return (this->value + value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator+=(const std::size_t value) noexcept
{
    this->value = (this->value + value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator-(const std::size_t value) const noexcept
{
    return (this->value + MOD - value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator-=(const std::size_t value) noexcept
{
    this->value = (this->value + MOD - value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator*(const std::size_t value) const noexcept
{
    return (this->value * value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator*=(const std::size_t value) noexcept
{
    this->value = (this->value * value) % MOD;
}

template <std::size_t MOD> ModuloInteger<MOD> ModuloInteger<MOD>::operator/(const std::size_t value) const noexcept
{
    return (this->value * ModuloInteger<MOD>(value).inv().value) % MOD;
}

template <std::size_t MOD> void ModuloInteger<MOD>::operator/=(const std::size_t value) noexcept
{
    this->value = (this->value * ModuloInteger<MOD>(value).inv().value) % MOD;
}

template <std::size_t MOD> std::ostream& operator<<(std::ostream& out, const ModuloInteger<MOD> value) noexcept
{
    out << value.value;
    return out;
}

using namespace std;

using modint = ModuloInteger<998244353>;

int main()
{
    int n;
    cin >> n;

    vector<int> ds(n);
    for (auto& d : ds)
    {
        cin >> d;
    }
    const int max_d = *max_element(ds.begin(), ds.end());

    vector<int> freq(max_d + 1, 0);
    for (auto d : ds)
    {
        freq[d]++;
    }

    if (ds[0] == 0 && freq[0] == 1)
    {
        modint ans(1);
        for (int i = 1; i <= max_d; i++)
        {
            modint base(freq[i - 1]);
            ans *= base.powi(freq[i]);
        }
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1024