#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 100000 + 5;
long long a[maxn];
long long power(long long a, long long k) {
  long long r = 1;
  a %= mod;
  while (k) {
    if (k & 1) r = r * a % mod;
    a = a * a % mod;
    k >>= 1;
  }
  return r;
}
int main() {
  long long n, x;
  scanf("%I64d%I64d", &n, &x);
  long long sum = 0;
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), sum += a[i];
  for (int i = 1; i <= n; i++) a[i] = sum - a[i];
  long long pnt = a[1];
  for (int i = 1; i <= n; i++) pnt = min(pnt, a[i]);
  for (int i = 1; i <= n; i++) a[i] -= pnt;
  priority_queue<long long, vector<long long>, greater<long long> > Que;
  for (int i = 1; i <= n; i++) Que.push(a[i]);
  while (1) {
    long long mn = Que.top(), cnt = 1, num;
    Que.pop();
    if (Que.empty()) {
      if (mn % x == 0 && mn != 0) mn /= x, pnt++;
      if (pnt < sum)
        printf("%I64d\n", power(x, pnt));
      else
        printf("%I64d\n", power(x, sum));
      return 0;
    }
    while (!Que.empty() && Que.top() == mn) Que.pop(), cnt++;
    if (cnt % x == 0) {
      pnt++;
      queue<long long> QQ;
      while (!Que.empty()) {
        num = Que.top();
        QQ.push(num - 1);
        Que.pop();
      }
      while (!QQ.empty()) {
        num = QQ.front();
        Que.push(num);
        QQ.pop();
      }
      for (int i = 0; i < cnt / x; i++) Que.push(mn);
    } else {
      if (pnt < sum)
        printf("%I64d\n", power(x, pnt));
      else
        printf("%I64d\n", power(x, sum));
      return 0;
    }
  }
  return 0;
}
