M=10**9+7 c=[0]*5000 N=input() for i in xrange(N):c[input()]+=1 a=[1]+[0]*N p=[1]+[0]*N for i in xrange(N): p[i+1]=p[i]*(i+1)%M for j in xrange(N,0,-1):a[j]=(a[j]+a[j-1]*c[i])%M r=0 for i in xrange(N+1):r=(r+(-1)**(i%2)*a[i]*p[N-i])%M print r