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)) import numpy as np n = int(input()) a = ([int(input()) for _ in range(n)]) count = [0]*n for v in (a): count[v] += 1 M = 10**9+7 ans = 0 dp = np.zeros(n+1, dtype=np.int64) dp[0] = 1 for k in range(n): v = count[k] if v==0: continue ndp = np.array(dp) ndp[1:] += dp[:-1]*v%M dp = ndp # 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] dp = dp.tolist() 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)