#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int mod = 1000000000 + 7;
long long num[maxn], a[maxn];
long long f(long long x, long long y) {
  long long res = 1, b = x;
  while (y) {
    if (y & 1) res = (res * b) % mod;
    b = (b * b) % mod;
    y >>= 1;
  }
  return res;
}
long long cal(long long x, long long y) {
  long long ret = 0;
  while (x && (x % y == 0)) {
    ret++;
    x /= y;
  }
  return ret;
}
int main() {
  int n, x;
  while (~scanf("%d%d", &n, &x)) {
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%I64d", &a[i]);
      sum += a[i];
    }
    for (int i = 0; i < n; ++i) num[i] = sum - a[i];
    sort(num, num + n);
    long long cnt = 0, ont = 1, op = num[0], tmp;
    int p = 0;
    while (true) {
      while (p + 1 < n && num[p + 1] - cnt == op) ont++, p++;
      cnt += op;
      if ((ont % x) || (op == 0)) {
        tmp = min(cnt, sum);
        long long ans = f(x, tmp);
        printf("%I64d\n", ans);
        break;
      }
      op = cal(ont, x);
      if (p + 1 < n) op = min(op, num[p + 1] - cnt);
      for (int i = 0; i < op; ++i) ont /= x;
    }
  }
  return 0;
}
