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]; dp[0] = 1; for (int i = 0; i < N; i++) { for (int j = N - 1; j >= 0; j--) { dp[j + 1] += dp[j] * hates[i]; dp[j + 1] %= 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[j] * factor[N - j] % MOD; } else { ans -= dp[j] * factor[N - j] % MOD; if (ans < 0) { ans += MOD; } } } System.out.println(ans); } public static void main(String[] args) { new Main().solve(); } }