#include #include #include #include using ll = long long; constexpr ll MOD = 1000000007; template constexpr std::pair extgcd(const T a, const T b) { if (b == 0) { return std::pair{1, 0}; } const auto p = extgcd(b, a % b); return {p.second, p.first - p.second * (a / b)}; } template constexpr T inverse(const T a, const T mod = MOD) { return (mod + extgcd(a, mod).first % mod) % mod; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int N; std::cin >> N; assert(1 <= N and N < 2e5); ll P; std::cin >> P; assert(1 <= P and P < MOD); std::vector fact(2 * N + 1, 1), inv(2 * N + 1, 1); for (ll i = 2; i <= 2 * N; i++) { fact[i] = (fact[i - 1] * i) % MOD, inv[i] = ((MOD - MOD / i) * inv[MOD % i]) % MOD; } for (int i = 1; i <= 2 * N; i++) { (inv[i] *= inv[i - 1]) %= MOD; } std::vector R(N, 0); for (int i = 0, a; i < N; i++) { std::cin >> a, assert(0 <= a and a < N), R[a]++; } ll ans = P, sum = 0; int zero = 0; for (int i = N - 1, k = 0; i >= 0; k += R[i], i--) { const int r = R[i]; if (r == 0) { continue; } const ll Q = (P * r + k) % MOD; if (Q == 0) { sum = (r * fact[r + k - 1] % MOD) * inv[k] % MOD, zero++; } else { (sum += r * inverse(Q) % MOD) %= MOD; (((ans *= fact[r + k - 1] * inv[k] % MOD) %= MOD) *= Q) %= MOD; } } std::cout << (zero >= 2 ? 0LL : ans * sum % MOD) << std::endl; }