#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long N = 3e5 + 7;
long long n, x;
long long arr[N];
long long pwr(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res % 1000000007;
}
void solve() {
  cin >> n >> x;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  vector<long long> vec;
  for (long long i = 0; i < n; i++) vec.push_back(sum - arr[i]);
  sort(vec.rbegin(), vec.rend());
  while (1) {
    long long v = vec.back(), cnt = 0;
    while (!vec.empty() and v == vec.back()) {
      vec.pop_back();
      cnt++;
    }
    if (cnt % x) {
      v = min(v, sum);
      cout << pwr(x, v);
      return;
    } else {
      for (long long i = 0; i < cnt / x; i += 1) {
        vec.push_back(v + 1);
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
