#include typedef long long LL; const int N = 5000 + 7; const int MOD = 1e9 + 7; int n, fac[N], f[N], a[N]; int main() { scanf("%d", &n); for(int i = 1, x; i <= n; ++i) { scanf("%d", &x); ++a[x + 1]; } fac[0] = 1; for(int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % MOD; f[0] = 1; for(int i = 1; i <= n; ++i) for(int j = i; j >= 1; --j) f[j] = (f[j] + 1LL * f[j - 1] * a[i]) % MOD; int ans = 0; for(int i = 0; i <= n; ++i) ans = (ans + (i & 1 ? -1LL : 1LL) * f[i] * fac[n - i]) % MOD; printf("%d\n", (ans + MOD) % MOD); return 0; }