#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>N; FOR(i,N) cin>>A[i], X[A[i]]++; dp[0]=1; FOR(i,N) { for(x=N;x>=0;x--) if(dp[x]) (dp[x+1] += X[i]*dp[x]) %= mo; } ll ret=0; FOR(x,N+1) ret += ((x%2)?(-1):1)*dp[x]*fact[N-x]%mo; cout<<(ret%mo+mo)%mo<