md = 10**9+7 from array import array import numpy as np n = int(input()) cnt = array("I", [0]*n) for _ in range(n): a = int(input()) cnt[a] += 1 dp = np.zeros(n+1, "i8") dp[0] = 1 for a in range(n): if cnt[a] == 0: continue dp[1:n+1] += dp[:n]*cnt[a] dp %= 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)