import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) a = [int(input()) for _ in range(n)] from collections import Counter count = Counter(a) M = 10**9+7 ans = 0 dp = [0]*(n+1) dp[0] = 1 for k,v in count.items(): ndp = [0]*(n+1) for b in range(n): val = dp[b] if val==0: continue ndp[b] += val ndp[b+1] += v*val%M ndp[b] %= M ndp[b+1] %= M dp = ndp g = [1] for i in range(1,n+1): g.append(g[-1]*i%M) s = 1 for i in range(n+1): ans += s * dp[i] * g[n-i] % M ans %= M s *= -1 print(ans%M)