#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 1.1e5, MO = 1e9 + 7;
ll n, x, a[N];
ll power(ll x, ll pw) {
  ll ret = 1;
  for (ll i = 1; i <= pw; i <<= 1, x = x * x % MO)
    if (pw & i) ret = ret * x % MO;
  return ret;
}
void init() {
  cin >> n >> x;
  for (ll i = 1; i <= (ll)(n); ++i) cin >> a[i];
}
void solve() {
  ll sum = 0;
  for (ll i = 1; i <= (ll)(n); ++i) sum += a[i];
  if (sum == 0 || n == 1) {
    cout << 1;
    return;
  }
  map<ll, ll> mp;
  for (ll i = 1; i <= (ll)(n); ++i) ++mp[sum - a[i]];
  ll t;
  for (;;) {
    auto iter = mp.begin();
    t = iter->first;
    ll cnt = iter->second;
    mp.erase(iter);
    if (cnt % x)
      break;
    else {
      mp[t + 1] += cnt / x;
    }
  }
  cout << power(x, min(t, sum));
}
void test() {
  if (dbg) {
  }
}
}  // namespace
int main() {
  if (!dbg) {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
  cout << fixed << setprecision(20);
  init();
  solve();
  test();
  return 0;
}
