#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vector<int> arr(n);
  ll sum = 0LL;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += 1LL * arr[i];
  }
  map<ll, int> cnt;
  for (int i = 0; i < n; ++i) {
    ++cnt[sum - arr[i]];
  }
  ll val;
  auto it = cnt.begin();
  while (true) {
    if (it->second % x) {
      val = it->first;
      break;
    }
    cnt[it->first + 1] += (it->second / x);
    ++it;
  }
  val = min(val, sum);
  vector<ll> lg2(64);
  lg2[0] = x;
  for (int i = 1; i < 64; ++i) {
    lg2[i] = (lg2[i - 1] * lg2[i - 1]) % MOD;
  }
  ll sol = 1LL;
  while (val) {
    ll lg = ll(log2(val));
    val -= (1LL << lg);
    sol = (sol * lg2[lg]) % MOD;
  }
  cout << sol;
  return 0;
}
