#include <bits/stdc++.h>
using namespace std;
long long A[100005], sum, x;
int n, cnt, k;
long long mod = 1000000007ll;
multiset<long long> ms;
multiset<long long>::iterator it;
long long f(long long x, long long y) {
  if (y == 0ll)
    return 1ll;
  else if (y == 1ll)
    return x % mod;
  else {
    long long tmp = f(x, y / 2ll);
    tmp = tmp * tmp % mod;
    if (y % 2ll == 0ll)
      return tmp;
    else
      return tmp * x % mod;
  }
}
void print_ms() {
  for (it = ms.begin(); it != ms.end(); it++) printf("%lld ", *it);
  printf("\n------------\n");
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (0); i < (n); i++) {
    scanf("%lld", &A[i]);
    sum += A[i];
  }
  for (int i = (0); i < (n); i++) A[i] = sum - A[i];
  for (int i = (0); i < (n); i++) ms.insert(A[i]);
  while (1) {
    x = *ms.begin();
    cnt = ms.count(x);
    if (cnt % k != 0)
      break;
    else {
      for (int i = (0); i < (cnt); i++) ms.erase(ms.find(x));
      cnt = cnt / k;
      for (int i = (0); i < (cnt); i++) ms.insert(x + 1ll);
    }
  }
  printf("%lld\n", f((long long)k, min(x, sum)));
  return 0;
}
