import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { final long MOD = 1_000_000_000 + 7; long[] fac = new long[10000]; { fac[0] = 1; for (int i = 1; i < fac.length; ++i) fac[i] = fac[i - 1] * i % MOD; } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] A = new int[N]; int[] cnt = new int[5000]; for (int i = 0; i < N; ++i) { A[i] = sc.nextInt(); ++cnt[A[i]]; } long[] f = new long[N + 1]; f[0] = 1; for (int i = 0; i <= N - 1; ++i) { for (int j = N - 1; j >= 0; --j) { f[j + 1] += f[j] * cnt[i] % MOD; f[j + 1] %= MOD; } } long ans = 0; for (int i = 0; i <= N; ++i) { ans += fac[N - i] * f[i] % MOD * (i % 2 == 0 ? 1 : MOD - 1) % MOD; ans %= MOD; } System.out.println(ans); } public static void main(String[] args) { new Main().run(); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }