#include #include #include using ll = long long; constexpr ll MOD = 1000000007; constexpr int MAX = 200000; ll dp[MAX]; int R[MAX]; ll fact[2 * MAX + 1]; ll inv[2 * MAX + 1]; 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; ll P; std::cin >> N >> P; std::fill(fact, fact + 2 * MAX + 1, 1), std::fill(inv, inv + 2 * MAX + 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; } for (int i = 0, a; i < N; i++) { std::cin >> a, R[a]++; } dp[0] = 1; for (int i = N - 1, k = 0, max = 0; i >= 0; k += R[i], i--) { const int r = R[i]; if (r == 0) { continue; } const ll alpha = (r * fact[r + k - 1] % MOD) * inv[k] % MOD; const ll beta = (k * fact[r + k - 1] % MOD) * inv[k] % MOD; for (int j = max; j >= 0; j--) { (dp[j + 1] += alpha * dp[j] % MOD) %= MOD, (dp[j] *= beta) %= MOD; } max++; } ll ans = 0; for (ll i = 0, p = 1; i <= N; i++, (p *= P) %= MOD) { (ans += (i * p % MOD) * dp[i] % MOD) %= MOD; } std::cout << ans << std::endl; }