#include <bits/stdc++.h>
using namespace std;
const int maxn = 120000;
const int mod = 1000000007;
int n, x;
int a[maxn];
map<long long, int> mp;
long long pow(long long x, long long m) {
  long long ans = 1, now = x;
  while (m) {
    if (m & 1) ans = (ans * now) % mod;
    m >>= 1;
    now = (now * now) % mod;
  }
  return ans;
}
int main() {
  cin >> n >> x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    long long now = sum - a[i];
    map<long long, int>::iterator it = mp.find(now);
    if (it != mp.end()) {
      it->second++;
      while (it->second >= x) {
        it->second -= x;
        mp[++now]++;
        it = mp.find(now);
      }
    } else
      mp[now]++;
  }
  long long ans = 0;
  for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (it->second != 0) {
      ans = it->first;
      break;
    }
  }
  ans = min(ans, sum);
  ans = pow(x, ans);
  cout << ans << endl;
  return 0;
}
