Problem:
C: Rebound Sequences
An integer sequence $a$ is
rebound sequence
if there are three integers $i, j, k$ ($1 \leq i < j < k \leq N$) satisfying $a_i > a_k > a_j$. You are given an integer sequence $s$. Your task is to count the number of rebound sequences that can be obtained by permuting the elements of $s$.
Input
The input consists of a single test case in the format below.
$N$
$s_1$ $s_2$ ... $s_N$
The first line contains a single integer $N$ ($1 \leq N \leq 200$). The second line contains $N$ integers $s_i$ ($1 \leq s_i \leq N$), which is the $i$-th element of $s$.
Output
Output the number of rebound sequences that can be obtained by permuting the elements of $s$ modulo $10^9 + 7$.
Examples
Input 1
4
1 2 3 4
Output 1
10
Input 2
12
1 2 3 4 5 6 7 8 9 10 11 12
Output 2
478793588
Input 3
5
3 1 4 1 5
Output 3
32
Input 4
20
1 1 1 2 3 4 4 7 7 8 11 12 13 14 15 16 17 17 19 20
Output 4
959127228

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

// template <unsigned mod> void rd(fp<mod> &x) {
//     fastio::rd(x.v);
// }
// template <unsigned mod> void wt(fp<mod> x) {
//     fastio::wt(x.v);
// }

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

using Fp = fp<1000000007>;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> B(N,0);
    rep(i,0,N) {
        int x;
        cin >> x;
        x--;
        B[x]++;
    }
    vector<int> A;
    rep(i,0,N) if (B[i] > 0) A.push_back(B[i]);
    N = A.size();
    vector<Fp> DP(1,0);
    int Cur = 0;
    DP[0] = 1;
    rep(i,0,N) {
        vector<Fp> NewDP(Cur+A[i]+1,0);
        rep(j,0,Cur+1) {
            rep(k,0,j+1) {
                rep(l,1,A[i]+1) {
                    if (k == 0) {
                        if (l != A[i]) continue;
                        NewDP[j-k+l] += DP[j];
                    }
                    else {
                        NewDP[j-k+l] += DP[j] * nCr<Fp>(A[i]-l+k-1,k-1);
                    }
                }
            }
        }
        Cur += A[i];
        swap(DP,NewDP);
    }
    Fp ANS = Fact<Fp>(Cur);
    rep(i,0,N) ANS *= Fact<Fp>(A[i],true);
    rep(i,0,Cur+1) ANS -= DP[i];
    cout << ANS << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3512
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const ll mod = 1e9+7;

int M = 222;
ll fac[222];
ll inv[222];

ll C(int n, int k){
	if(n < k)return 0;
	if(n < 0)return 0;
	if(k < 0)return 0;
	ll ret = fac[n];
	ret *= inv[k];
	ret %= mod;
	ret *= inv[n-k];
	ret %= mod;
	return ret;
}

ll modpow(ll a, ll b){
	if(b == 0)return 1;
	if(b % 2 == 0){
		ll t = modpow(a, b/2);
		t *= t;
		t %= mod;
		return t;
	}
	ll t = modpow(a, b-1);
	t *= a;
	t %= mod;
	return t;
}

int main(){
	int N; cin >> N;
	vector<int> A(N);
	vector<int> cnt(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
		--A[i];
		cnt[A[i]]++;
	}
	sort(A.begin() , A.end());
	fac[0] = 1;
	for(int i = 1; i < M; i++){
		fac[i] = fac[i-1] * i;
		fac[i] %= mod;
	}
	inv[M-1] = modpow(fac[M-1], mod-2);
	for(int i = M-2; i >= 0; i--){
		inv[i] = inv[i+1] * (i+1);
		inv[i] %= mod;
	}	
	vector<vector<ll>> dp(N+1 , vector<ll>(N+2));
	dp[0][1] = 1;
	for(int i = 0; i < N; i++){
		if(cnt[i] == 0){
			dp[i+1] = dp[i];
			continue;
		}
		for(int j = 0; j <= N+1; j++){
			for(int k = 0; k < j; k++){
				for(int l = 1; l <= cnt[i]; l++){
					if(j-k+l > N+1)continue;
					if(k == 0){
						if(l != cnt[i])continue;
						dp[i+1][j-k+l] += dp[i][j];
						dp[i+1][j-k+l] %= mod;
					}
					else{
						dp[i+1][j-k+l] += dp[i][j] * C(cnt[i]-l+k-1, cnt[i]-l);
						dp[i+1][j-k+l] %= mod;
					}
				}
			}
		}
	}
	ll ans = fac[N];
	for(int i = 0; i < N; i++){
		ans *= inv[cnt[i]];
		ans %= mod;
	}
	for(int i = 0; i <= N+1; i++){
		ans += mod - dp[N][i];
		ans %= mod;
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3776
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

// FFT library by QCFium
// https://judge.yosupo.jp/submission/127261
template<typename base_t, typename promoted_t, base_t mod> struct mod_int {
	static_assert(std::is_signed<base_t>::value, "base_t must be signed");
	static base_t get_mod() { return mod; }
	base_t x = 0;
	mod_int () = default;
	mod_int (int64_t x_) : x(x_ % mod) { if (x < 0) x += mod; }
	static mod_int raw(base_t x) { mod_int res; res.x = x; return res; }
	mod_int &operator += (mod_int p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	mod_int &operator -= (mod_int p) {
		if ((x -= p.x) < 0) x += mod;
		return *this;
	}
	mod_int &operator *= (mod_int p) { x = (promoted_t) x * p.x % mod; return *this; }
	mod_int &operator /= (mod_int p) { return (*this *= p.inv()); }
	mod_int &operator ^= (int64_t p) {
		mod_int res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	mod_int operator - () const { return mod_int::raw(x ? mod - x : 0); }
	mod_int operator + (mod_int p) const { return mod_int(*this) += p; }
	mod_int operator - (mod_int p) const { return mod_int(*this) -= p; }
	mod_int operator * (mod_int p) const { return mod_int(*this) *= p; }
	mod_int operator / (mod_int p) const { return mod_int(*this) /= p; }
	mod_int operator ^ (int64_t p) const { return mod_int(*this) ^= p; }
	bool operator == (mod_int p) const { return x == p.x; }
	bool operator != (mod_int p) const { return x != p.x; }
	explicit operator base_t() const { return x; }
	mod_int inv() const {
		base_t a = x, b = mod, u = 1, v = 0;
		while (b > 0) {
			base_t t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return mod_int(u);
	}
	friend std::ostream &operator << (std::ostream &stream, mod_int<base_t, promoted_t, mod> p) { return stream << p.x; }
};
template<int mod> using mod_int32 = mod_int<int, uint64_t, mod>;
template<int64_t mod> using mod_int64 = mod_int<int64_t, __int128_t, mod>;



template<typename base_t, typename promoted_t, typename promoted_signed_t, base_t mod> struct mod_int_montgomery {
	using self = mod_int_montgomery;
	using signed_base_t = typename std::make_signed<base_t>::type;
	/*
	using promoted_signed_t = typename std::conditional<std::is_same<promoted_t, __uint128_t>::value,
		__int128_t, typename std::make_signed<promoted_t>::type>::type;*/
	static constexpr int BASE_BITS = sizeof(base_t) * 8;
	
	static base_t get_mod() { return mod; }
	static constexpr base_t inv_mod2_32(base_t x) { // modulo inverse mod 2^BASE_BITS, tensai
		base_t res = x; // res * x == 1 mod 2^2
		for (int i = 2; i < BASE_BITS; i <<= 1) res *= 2 - res * x; // res * x = 1 + k(2^m) -> (new res) * x = 1 - (k(2^m))^2
		return res;
	}
	// r == 2^BASE_BITS
	static constexpr base_t minus_mod_inv = -inv_mod2_32(mod);
	static constexpr base_t r2 = -promoted_t(mod) % mod; // r^2 mod MOD
	static constexpr base_t mod2 = mod * 2;
	
	static constexpr base_t reduce(promoted_t x) {
		return (x + promoted_t(base_t(x) * minus_mod_inv) * mod) >> BASE_BITS;
	}
	
	base_t x_;
	mod_int_montgomery () : x_(0) {}
	mod_int_montgomery (promoted_signed_t x) : x_(reduce((promoted_t) (x % mod + mod) * r2)) {}
	static mod_int_montgomery raw(base_t x) { self res; res.x_ = reduce((promoted_t) x * r2); return res; }
	
	self &operator += (const self &r) {
		if ((x_ += r.x_) >= mod2) x_ -= mod2;
		return *this;
	}
	self &operator -= (const self &r) {
		x_ = x_ < r.x_ ? x_ - r.x_ + mod2 : x_ - r.x_;
		return *this;
	}
	self &operator *= (const self &r) {
		x_ = reduce((promoted_t) x_ * r.x_);
		return *this;
	}
	self &operator /= (const self &r) { return (*this *= r.inv()); }
	self &operator ^= (int64_t p) {
		self res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	self operator + (const self &r) const { return self(*this) += r; }
	self operator - (const self &r) const { return self(*this) -= r; }
	self operator * (const self &r) const { return self(*this) *= r; }
	self operator / (const self &r) const { return self(*this) /= r; }
	self operator ^ (int64_t p) const { return self(*this) ^= p; }
	self operator - () const { self res; res.x_ = x_ ? mod2 - x_ : 0; return res; }
	
	static base_t normalized(base_t x) { return x >= mod ? x - mod : x; }
	bool operator == (const self &r) const { return normalized(x_) == normalized(r.x_); }
	bool operator != (const self &r) const { return normalized(x_) != normalized(r.x_); }
	explicit operator signed_base_t () const { return normalized(reduce(x_)); }
	
	self inv() const {
		signed_base_t a = (signed_base_t) *this, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return self(u);
	}
	friend std::ostream &operator << (std::ostream &stream, const self &p) {
		return stream << (signed_base_t) p;
	}
	friend std::istream &operator >> (std::istream &stream, self &a) {
		int64_t x;
		stream >> x;
		a = self(x);
		return stream;
	}
};
template<uint32_t mod> using mod_int_montgomery32 = mod_int_montgomery<uint32_t, uint64_t, int64_t, mod>;
template<uint64_t mod> using mod_int_montgomery64 = mod_int_montgomery<uint64_t, __uint128_t, __int128_t, mod>;





template<typename mint> struct NTT { // mint version
	static int get_proot(int p = 1) {
		int k = __builtin_ctzll(get_mod() - 1);
		auto m = (get_mod() - 1) >> k;
		for (decltype(m) i = 1; i <= m; i++) if (m % i == 0) for (int j = 0; j <= k; j++) 
			if ((i < m || j < k) && (mint(p) ^ (i << j)) == 1) return get_proot(p + 1);
		return p;
	}
	static constexpr decltype(mint::get_mod()) get_mod() { return mint::get_mod(); }
	mint dw[30], idw[30];
	NTT () {
		mint proot = get_proot();
		for (int i = 0; i < 30; i++) dw[i] = -(mint(proot) ^ ((get_mod() - 1) >> (i + 2)));
		for (int i = 0; i < 30; i++) idw[i] = mint(1) / dw[i];
	}
	void ntt(std::vector<mint> &a) const {
		size_t n = a.size();
		assert(!(n & (n - 1)));
		for (size_t m = n; m >>= 1; ) {
			mint w = 1;
			for (size_t s = 0, k = 0; s < n; s += 2 * m) {
				for (size_t i = s; i < s + m; i++) {
					auto x = a[i], y = a[i + m] * w;
					a[i] = x + y, a[i + m] = x - y;
				}
				w *= dw[__builtin_ctzll(++k)];
			}
		}
	}
	void intt(std::vector<mint> &a) const {
		size_t n = a.size();
		assert(!(n & (n - 1)));
		for (size_t m = 1; m < n; m <<= 1) {
			mint w = 1;
			for (size_t s = 0, k = 0; s < n; s += 2 * m) {
				for (size_t i = s; i < s + m; i++) {
					auto x = a[i], y = a[i + m];
					a[i] = x + y, a[i + m] = (x - y) * w;
				}
				w *= idw[__builtin_ctzll(++k)];
			}
		}
		auto inv = mint(1) / mint(n);
		for (auto &i : a) i *= inv;
	}
	std::vector<mint> convolve_self(std::vector<mint> a) const {
		if (!a.size()) return {};
		size_t n_ = a.size() * 2 - 1;
		size_t n = 1;
		for (; n < n_; n <<= 1);
		a.resize(n); ntt(a);
		for (auto &i : a) i *= i;
		intt(a);
		a.resize(n_);
		return a;
	}
	std::vector<mint> convolve(std::vector<mint> a, std::vector<mint> b) const {
		if (!a.size() || !b.size()) return {};
		size_t n_ = a.size() + b.size() - 1;
		size_t n = 1;
		for (; n < n_; n <<= 1);
		a.resize(n); ntt(a);
		b.resize(n); ntt(b);
		for (size_t i = 0; i < n; i++) a[i] *= b[i];
		intt(a);
		a.resize(n_);
		return a;
	}
};

template<typename res_t, typename mint0, typename mint1, typename mint2> std::vector<res_t> restore(
	const std::vector<mint0> &a, const std::vector<mint1> &b, const std::vector<mint2> &c) {
	
	int mod0 = mint0::get_mod(), mod1 = mint1::get_mod(), mod2 = mint2::get_mod();
	int mod0_mod1 = (int) mint1(mod0).inv();
	int mod0mod1_mod2 = (int) (mint2(mod0) * mint2(mod1)).inv();
	int mod0mod1 = (int) (res_t(mod0) * res_t(mod1));
	int n = a.size();
	std::vector<res_t> res(n);
	for (int i = 0; i < n; i++) {
		int64_t mod0_coef = (int64_t) (mod1 + (int) b[i] - (int) a[i]) * mod0_mod1 % mod1;
		if (mod0_coef < 0) mod0_coef += mod1;
		int64_t t = (int) a[i] + mod0 * mod0_coef;
		int64_t mod1_coef = (int64_t) ((int) c[i] - t % mod2) * mod0mod1_mod2 % mod2;
		if (mod1_coef < 0) mod1_coef += mod2;
		t += mod0mod1 * mod1_coef;
		res[i] = t;
	}
	return res;
}

using res_t = mod_int32<1000000007>;

template<typename mint> std::vector<mint> convolve(const std::vector<res_t> &a_, const std::vector<res_t> &b_) {
	std::vector<mint> a(a_.size());
	std::vector<mint> b(b_.size());
	for (size_t i = 0; i < a_.size(); i++) a[i] = (int) a_[i];
	for (size_t i = 0; i < b_.size(); i++) b[i] = (int) b_[i];
	NTT<mint> ntt;
	return ntt.convolve(a, b);
}



std::vector<res_t> solve2(const std::vector<res_t> &a, const std::vector<res_t> &b) {
	using mint0 = mod_int_montgomery32<998244353>;
	using mint1 = mod_int_montgomery64<1945555039024054273>;
	auto r0 = convolve<mint0>(a, b);
	auto r1 = convolve<mint1>(a, b);
	
	int n = r0.size();
	int mod1_mod0 = (int) mint0(mint1::get_mod()).inv();
	int mod1_resmod = mint1::get_mod() % res_t::get_mod();
	std::vector<res_t> res(n);
	for (int i = 0; i < n; i++) {
		int64_t t = (int64_t) r1[i];
		int64_t mod1_coef = ((int) r0[i] - t % mint0::get_mod()) * mod1_mod0 % mint0::get_mod();
		if (mod1_coef < 0) mod1_coef += mint0::get_mod();
		res[i] = (t + mod1_coef * mod1_resmod);
	}
	return res;
}



using ll = long long;


ll pow_mod(ll x, ll n, ll mod) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

ll comb_mod(ll n, ll r, ll mod, vector<ll> &fact, vector<ll> &inv) {
  if (n < r || r < 0) return 0;
  
  ll res = 1;
  if(n >= r) {
    res = fact[n] % mod;
    res = res * inv[r] % mod;
    res = res * inv[n-r] % mod;
  }
  return res;
}

const ll nmax = 2e5 + 100;
const ll MOD = 1e9 + 7;

vector<ll> fact(nmax, 0), inv(nmax, 0);


ll dp[210][210];
ll f[410][410];

void init() {
  for(ll i = 0; i < nmax; ++i) {
    if(i == 0) {fact[i] = 1;}
    else {fact[i] = fact[i-1] * i % MOD;}
  }
  for(ll i = nmax - 1; i >= 0; --i) {
    if(i == nmax - 1) {inv[i] = pow_mod(fact[i], MOD-2, MOD);}
    else {inv[i] = inv[i+1] * (i+1) % MOD;}
  }
  
  for (ll n = 0; n < 410; ++n) {
    for (ll sum = 0; sum < 410; ++sum) {
      f[sum][n] = comb_mod(sum + n - 1, sum, MOD, fact, inv);
    }
  }
  f[0][0] = 1;
  
  return;
}


int main() {
  init();
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  
  vector<int> cnt(210, 0);
  vector<int> sum(210, 0); // [0, n]
  for (int i = 0; i < N; ++i) {
    cnt[A[i]]++;
  }
  for (int v = 0; v < 210; ++v) {
    if (v > 0) sum[v] = sum[v - 1];
    sum[v] += cnt[v]; 
  }
  
  ll res = 0;
  dp[0][0] = 1;
  for (int n = 0; n <= N; ++n) {
    int s = sum[n], c = cnt[n+1];
    
    if (c == 0) {
      for (int j = 0; j < 210; ++j) {
        dp[n+1][j] = dp[n][j];
      }
      continue;
    }
    
    res *= f[c][s+1];
    res %= MOD;
    for (int j = 0; j < s; ++j) {
      ll d = (f[c][s+1] - f[c][s-j] + MOD) % MOD;
      res += d * dp[n][j];
      res %= MOD;
    }
    for (int c1 = 0; c1 < c; ++c1) {
      // for (int k = 0; k < s; ++k) {
      //   for (int j = 0; j <= k; ++j) {
      //     dp[n+1][c1+k] += dp[n][j] * f[c1][k-j];          
      //     dp[n+1][c1+k] %= MOD;
      //   }
      // }
      vector<res_t> va(s), vb(s);
      for (int j = 0; j < s; ++j) {
        va[j] = dp[n][j];
        vb[j] = f[c1][j];
      }
      vector<res_t> vc = solve2(va, vb);
      for (int k = 0; k < s; ++k) {
        dp[n+1][c1+k] += (int)vc[k];
        dp[n+1][c1+k] %= MOD;
      }
    }
    
    for (int c1 = 0; c1 < c; ++c1) {
      for (int k = 0; k < s; ++k) {
        dp[n+1][c1+k] += f[c1][k+1];
        dp[n+1][c1+k] %= MOD;
      }
    }
    dp[n+1][s+c] = 1;
    
    // cout << -1 << " " << n << " " << res << endl;
    // for (int k = 0; k <= s+c; ++k) {
    //   cout << k << " " << dp[n+1][k] << endl;
    // }
  }
  cout << res << endl;
  
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8320
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;

vvll FDP(201,vll(201,-1));

//S[L],...,S[R-1]に対する答え
ll f(ll L, ll R, vll& S) {
    if(FDP[L][R]>=0)return FDP[L][R];
    if (L + 1 > R||S[R-1]==S[L])return 1;

    ll NL = -1;
    for (ll i = L; i < R; i++)if (S[i] != S[L]) {
        NL = i;
        break;    
    }
    ll mcnt = NL - L,len = R - NL;
    vvll DP(len + 1, vll(mcnt + 1, 0));
    rep(i, mcnt + 1)DP[0][i] = 1;
    rep(i, len)rep(j, mcnt)rep(k, i + 2) {
        DP[i + 1][j + 1] += DP[k][j] * f(NL + k, NL + i + 1, S);
        DP[i + 1][j + 1] %= mod;
    }

    ll res = 0;
    rep(i, len + 1) {
        res += DP[i][mcnt] * f(NL + i, R, S);
        res %= mod;
    }
    FDP[L][R] = res;
    return res;
}


ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return (a*modpow(a,n-1))%mod;
    ll t=modpow(a,n/2);
    return (t*t)%mod;
}

ll falc(vll S){
    map<ll,ll> M;
    ll an=1,cnt=0;
    for(auto s:S){
        cnt++;
        M[s]++;
        an*=cnt;
        an%=mod;
        an*=modpow(M[s],mod-2);
        an%=mod;
    }
    return an;
}

int main() {
    ll N;
    cin >> N;
    vll S(N);
    rep(i, N)cin >> S[i];
    sort(S.begin(), S.end());
    ll an=falc(S);
    ll bn=f(0, N, S);
    cout<<(an-bn+mod)%mod<<endl;
}
accuracy: 1
time_ms: 1450
memory_kb: 4892
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;

ll naive(vll S) {
    ll N = S.size();
    ll cnt = 0;
    do {
        bool OK = 0;
        rep(k, N)rep(j, k)rep(i, j)if (S[i] > S[k] && S[k] > S[j])OK = 1;
        if (!OK) {
            cnt++;
            // rep(i, N)cout << S[i] << " \n"[i == N - 1];
        }
    } while (next_permutation(S.begin(), S.end()));
    return cnt;
}

vvll FDP(201,vll(201,-1));

ll ord=0;
//S[L],...,S[R-1]に対する答え
ll f(ll L, ll R, vll& S) {
    if(FDP[L][R]>=0)return FDP[L][R];
    if (L + 1 > R)return 1;
    if (S[R - 1] == S[L])return 1;//同じの

    ll NL = -1;
    for (ll i = L; i < R; i++) {
        if (S[i] != S[L]) {
            NL = i;
            break;
        }
    }
    ll mcnt = NL - L;
    ll len = R - NL;
    vvll DP(len + 1, vll(mcnt + 1, 0));
    rep(i, mcnt + 1)DP[0][i] = 1;
    rep(i, len) {
        rep(j, mcnt) {
            rep(k, i + 2) {
                ord++;
                DP[i + 1][j + 1] += DP[k][j] * f(NL + k, NL + i + 1, S);
                DP[i + 1][j + 1] %= mod;
            }
        }
    }

    ll res = 0;
    rep(i, len + 1) {
        res += DP[i][mcnt] * f(NL + i, R, S);
        res %= mod;
    }
    FDP[L][R] = res;
    return res;
}


ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return (a*modpow(a,n-1))%mod;
    ll t=modpow(a,n/2);
    return (t*t)%mod;
}

ll falc(vll S){
    map<ll,ll> M;
    ll an=1;
    ll cnt=0;
    for(auto s:S){
        cnt++;
        M[s]++;
        an*=cnt;
        an%=mod;
        an*=modpow(M[s],mod-2);
        an%=mod;
    }
    return an;
}

int main() {
    ll N=200;
    cin >> N;
    vll S(N);
    rep(i, N){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    // cout<<naive(S)<<endl;
    ll an=falc(S);
    ll bn=f(0, N, S);
    cout<<(an-bn+mod)%mod<<endl;

}
accuracy: 1
time_ms: 1490
memory_kb: 4880
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<>> _fact, _rfact, _inv;
  Combination(long long nsize = 5000000)
      : _fact(nsize + 1), _rfact(nsize + 1), _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for (int i = 1; i <= nsize; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for (int i = nsize - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int i = 1; i <= nsize; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<> fact(int k) const { return _fact[k]; }

  inline ModInt<> rfact(int k) const { return _rfact[k]; }

  inline ModInt<> inv(int k) const { return _inv[k]; }

  ModInt<> P(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<> C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  ModInt<> largeC(long long p, long long q) const {
    if (q < 0 || p < q) return 0;
    if (q >= (long long)_fact.size()) q = p - q;
    // if (q >= (long long)5000) q = p - q;
    ModInt<> res = rfact(q);
    for (int i = 0; i < q; ++i) res *= p - i;
    return res;
  }

  // n types,choose r
  ModInt<> H(int n, int r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }

  ModInt<> largeH(long long n, long long r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : largeC(n + r - 1, r);
  }

  ModInt<> Catalan(int n) {
    // C(2n,n) / (n + 1)
    return fact(2 * n) * rfact(n + 1) * rfact(n);
  }
};
using mint = ModInt<>;

int n;
vector<int> v;
vector<vector<bool>> ch;
vector<vector<mint>> dp;
Combination com;

mint solve();
mint calc(int rem, int rev, int id);

int main() {
  cin >> n;
  {
    vector<int> s(n);
    for (auto &p : s) cin >> p;
    sort(s.begin(), s.end(), greater<int>());
    for (int i = 0; i < n;) {
      int now = s[i], cnt = 0;
      while (i < n && now == s[i]) ++cnt, ++i;
      v.push_back(cnt);
    }
  }
  cout << solve() << endl;
  return 0;
}

mint solve() {
  ch.assign(n + 1, vector<bool>(n + 1, 0));
  dp.assign(n + 1, vector<mint>(n + 1, 0));
  ch[0][0] = 1;
  dp[0][0] = 1;
  mint res = com.fact(n);
  for (auto p : v) res *= com.rfact(p);
  res -= calc(n, 0, 0);
  return res;
}

mint calc(int rem, int rev, int id) {
  if (ch[rem][rev]) return dp[rem][rev];
  ch[rem][rev] = 1;
  int cnt = v[id];
  mint res = 0;
  if (cnt <= rev) res = calc(rem, rev - cnt, id + 1);
  for (int i = 0; i <= min(cnt - 1, rev); ++i)
    if (rem >= cnt - i)
      for (int j = 0; j < rem; ++j)
        if (rem - j >= cnt - i)
          res += calc(j, rev + rem - cnt - j, id + 1) *
                 com.C(rem - j - 1, cnt - i - 1);
  return dp[rem][rev] = res;
}
accuracy: 1
time_ms: 60
memory_kb: 61844
final_rank: 7

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

constexpr int MOD = 1000000007;
long long int power(long long int base, int exp) {
	long long int result{ 1 };
	while (exp > 0) {
		if (exp & 1) {
			result = result * base % MOD;
		}
		base = base * base % MOD;
		exp >>= 1;
	}
	return result;
}
bool is_rebound(const std::vector<int>& sequence) {
	for (auto i = 0; i < sequence.size(); ++i) {
		for (auto j = i + 1; j < sequence.size(); ++j) {
			if (sequence[i] <= sequence[j]) continue;
			for (auto k = j + 1; k < sequence.size(); ++k) {
				if (sequence[i] > sequence[k] && sequence[k] > sequence[j]) {
					return true;
				}
			}
		}
	}
	return false;
}
int show_not_rebound(std::vector<int> sequence) {
	std::sort(sequence.begin(), sequence.end());
	int count{ 0 };
	do {
		if (!is_rebound(sequence)) {
			for (auto i = 0; i < sequence.size(); ++i) {
				if (i > 0) std::cout << ' ';
				std::cout << sequence[i];
			}
			std::cout << '\n';
		}
		else {
			++count;
		}
	} while (std::next_permutation(sequence.begin(), sequence.end()));
	return count;
}

std::vector<std::vector<long long int>> memo;
std::function<long long int(const int, const int)> combination;
std::vector<int> frequency;
long long int func(const int current, const int length) {
	if (current == 0) return frequency[current] == length ? 1 : 0;
	if (memo[current][length] >= 0) return memo[current][length];
	const auto count = frequency[current];
	const auto min_count = std::accumulate(frequency.begin(), std::next(frequency.begin(), current), 0);
	if (count + min_count < length) return memo[current][length] = 0;
	long long int result{ 0 };
	for (auto last = 1; last <= count; ++last) {
		if (last > length) break;
		const auto rest = count - last;
		const auto right = length - last;
		if (last == count) 
			result += func(current - 1, right);
		for (auto left = 1; left + right <= min_count; ++left) {
			const auto under_pattern = func(current - 1, left + right);
			const auto rest_pattern = combination(left + rest - 1, rest);
			result += under_pattern * rest_pattern % MOD;
		}
	}
	return memo[current][length] = result % MOD;
}
int main() {
	int n; std::cin >> n;
	std::vector<int> sequence(n);
	for (auto &s : sequence) std::cin >> s;
	frequency.resize(n + 1);
	for (const auto s : sequence) {
		++frequency[s];
	}
	frequency.erase(std::remove(frequency
		.begin(), frequency.end(), 0), frequency.end());
	//std::cout << show_not_rebound(sequence) << '\n';
	memo.resize(frequency.size(), std::vector<long long int>(n + 1, -1));
	std::vector<long long int> factorial(n + 1, 1);
	for (auto i = 2; i <= n; ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
	}
	auto inverse = factorial; inverse[n] = power(factorial[n], MOD - 2);
	for (auto i = n; i > 1; --i) {
		inverse[i - 1] = i * inverse[i] % MOD;
	}
	combination = [factorial, inverse](const int n, const int r) {
		return n >= r ? factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD : 0;
	};
	long long int not_rebound{ 0 };
	for (auto len = 0; len <= n; ++len) {
		not_rebound += func(frequency.size() - 1, len);
	}
	not_rebound %= MOD;
	long long int all{ factorial[n] };
	for (const auto count: frequency) {
		all = all * inverse[count] % MOD;
	}
	std::cout << (all - not_rebound + MOD) % MOD << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3792
final_rank: 3