md = 10**9+7 from array import array n = int(input()) cnt = array("I", [0]*n) for _ in range(n): a = int(input()) cnt[a] += 1 dp = array("L", [1]+[0]*n) for a in range(n): if cnt[a] == 0: continue for i in range(n)[::-1]: dp[i+1] += dp[i]*cnt[a]%md ans = 0 f = 1 for i in range(n+1)[::-1]: cur = dp[i]*f%md if i & 1: ans -= cur else: ans += cur ans %= md f = f*(n+1-i)%md print(ans)