from collections import Counter N=int(input()) A=[int(input()) for i in range(N)] C=Counter(A) mod=10**9+7 FACT=[1] for i in range(1,2*10**5+1): FACT.append(FACT[-1]*i%mod) DP=[0]*(N+1) DP[0]=1 for v in C.values(): for i in range(N-1,-1,-1): DP[i+1]+=DP[i]*v DP[i+1]%=mod ANS=0 for i in range(N+1): x=FACT[N-i] if i%2==0: ANS+=x*DP[i] else: ANS-=x*DP[i] ANS%=mod print(ANS)