#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res % 1000000007 * x % 1000000007) % 1000000007;
    x = (x % 1000000007 * x % 1000000007) % 1000000007;
    y = y >> 1;
  }
  return res;
}
long long a[100005], pre[100005];
long long n, x;
long long cal(long long t) {
  long long cnt = 0;
  while (t > 0 && (t % x == 0)) {
    t = t / x;
    cnt++;
  }
  return cnt;
}
map<long long, long long> mpp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  long long i;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long tot = 0;
  for (i = 1; i <= n; i++) tot = (tot + a[i]);
  for (i = 1; i <= n; i++) {
    pre[i] = (tot - a[i]);
    mpp[pre[i]]++;
  }
  long long sum = 0;
  long long cur = tot;
  auto it = mpp.begin();
  while (it != mpp.end()) {
    long long t = it->first;
    long long y = it->second;
    long long cnt = 0;
    while (y > 0 && y % x == 0) {
      y = y / x;
      cnt++;
    }
    if (cnt)
      mpp[t + cnt] += y;
    else {
      cur = min(cur, t);
      break;
    }
    it++;
  }
  sum = (sum % 1000000006 + cur % 1000000006) % 1000000006;
  long long p = power(x, sum);
  cout << p;
  return 0;
}
