#include #include #include #include #include #include template Tp gcd(Tp a, Tp b, Tp& x, Tp& y) { x = Tp(0); y = Tp(1); for (Tp u = y, v = x; a;) { Tp q = b/a; std::swap(x -= q*u, u); std::swap(y -= q*v, v); std::swap(b -= q*a, a); } return b; } template Tp modinv(Tp a, Tp mod) { Tp x, y; gcd(a, mod, x, y); x %= mod; if (x < 0) x += mod; return x; } template Tp modadd(Tp a, Tp b, Tp mod) { a += b % mod; if (a < 0) a += mod; if (a >= mod) a -= mod; return a; } template Tp modadd(std::initializer_list const& adds, Tp mod) { Tp res = 0; for (auto const& add: adds) { res += add % mod; if (res < 0) res += mod; if (res >= mod) res -= mod; } return res; } template Tp modsub(Tp a, Tp b, Tp mod) { a -= b % mod; if (a < 0) a += mod; if (a >= mod) a -= mod; return a; } template Tp modmul(std::initializer_list const& muls, Tp mod) { Tp res = 1; for (auto const& mul: muls) (res *= mul) %= mod; return res; } template Tp modpow(Tp base, intmax_t iexp, Tp mod) { Tp res = 1; for (Tp dbl = base; iexp; iexp >>= 1) { if (iexp & 1) res = res * dbl % mod; dbl = dbl * dbl % mod; } return res; } class modfactorial { std::vector fact, fact_inv; intmax_t mod; public: modfactorial(intmax_t N, intmax_t mod): mod(mod) { fact.resize(N+1); fact_inv.resize(N+1); fact[0] = 1; for (intmax_t i = 1; i <= N; ++i) fact[i] = fact[i-1] * i % mod; fact_inv[N] = modinv(fact[N], mod); for (intmax_t i = N; i--;) fact_inv[i] = fact_inv[i+1] * (i+1) % mod; } intmax_t operator ()(intmax_t k) const { return fact[k]; } intmax_t inverse(intmax_t k) const { return fact_inv[k]; } }; constexpr intmax_t operator ""_jd(unsigned long long n) { return n; } constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; } constexpr size_t operator ""_zu(unsigned long long n) { return n; } // constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; } constexpr intmax_t mod = 1e9+7; int main() { size_t n; scanf("%zu", &n); std::vector b(n); for (size_t i = 0; i < n; ++i) { size_t a; scanf("%zu", &a); if (a >= n) continue; ++b[a]; } std::vector dp{1}; for (size_t i = 0; i < n; ++i) { std::vector tmp(i+2); for (size_t j = 0; j <= i; ++j) { (tmp[j] += dp[j]) %= mod; (tmp[j+1] += dp[j] * b[i]) %= mod; } dp = std::move(tmp); } modfactorial mf(n+1, mod); for (size_t i = 0; i <= n; ++i) { (dp[i] *= mf(n-i)) %= mod; } intmax_t res = 0; for (size_t i = 0; i <= n; ++i) { intmax_t cur = dp[i]; if (i % 2) cur = (mod-cur) % mod; (res += cur) %= mod; } printf("%jd\n", res); }