#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long N = 2e5 + 5;
const long long mod = 1000000007;
namespace modop {
long long madd(long long a, long long b) { return (a + b) % mod; }
long long msub(long long a, long long b) {
  return (((a - b) % mod) + mod) % mod;
}
long long mmul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long mpow(long long base, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp % 2 == 1) {
      res = (res * base) % mod;
    }
    exp >>= 1;
    base = (base * base) % mod;
  }
  return res;
}
long long minv(long long base) { return mpow(base, mod - 2); }
long long mdiv(long long a, long long b) { return mmul(a, minv(b)); }
}  // namespace modop
using namespace modop;
long long v[N];
long long n, x;
long long total = 0;
void testCase() {
  cin >> n >> x;
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
    total += v[i];
  }
  for (long long i = 1; i <= n; i++) {
    v[i] = total - v[i];
  }
  sort(v + 1, v + n + 1);
  map<long long, long long> mpp;
  for (long long i = 1; i <= n; i++) {
    mpp[v[i]]++;
  }
  set<pair<long long, long long> > st;
  for (auto it : mpp) {
    st.insert({it.first, it.second});
  }
  long long delta = 0, ans = 0;
  while (!st.empty()) {
    auto it = *st.begin();
    st.erase(it);
    long long remaining = it.first - delta;
    ans += remaining;
    if (it.second % x != 0) {
      break;
    } else {
      long long add = it.second / x;
      if (mpp[it.first + 1] > 0) st.erase({it.first + 1, mpp[it.first + 1]});
      mpp[it.first + 1] += add;
      st.insert({it.first + 1, mpp[it.first + 1]});
    }
    delta = it.first;
  }
  long long last = min(total, ans);
  cout << mpow(x, last) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) testCase();
  return 0;
}
