import java.util.Scanner; public class Main { private final int MOD = 1000000007; public void solve() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] hates = new int[N]; for (int i = 0; i < N; i++) { hates[scanner.nextInt()]++; } scanner.close(); // dp[i][j]:= i番目の出席番号までだけ見て、 // j個の出席番号が嫌いな人に割り当てられている数 long[][] dp = new long[N + 1][N + 1]; dp[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { dp[i + 1][j] = dp[i][j]; if (j == 0) { continue; } dp[i + 1][j] += dp[i][j - 1] * hates[i]; dp[i + 1][j] %= MOD; } } // factor[i] = i! long[] factor = new long[N + 1]; factor[0] = 1; for (int i = 1; i <= N; i++) { factor[i] = factor[i - 1] * i; factor[i] %= MOD; } long ans = 0; for (int j = 0; j <= N; j++) { if (j % 2 == 0) { ans += dp[N][j] * factor[N - j] % MOD; } else { ans -= dp[N][j] * factor[N - j] % MOD; if (ans < 0) { ans += MOD; } } System.out.println(ans % MOD); } System.out.println(ans); } public static void main(String[] args) { new Main().solve(); } }