#include <bits/stdc++.h>
using namespace std;
int x, n;
long long a[100010];
long long Pow(long long var, long long times) {
  long long res = 1;
  while (times) {
    if (times & 1) res = res * var % 1000000007;
    var = var * var % 1000000007;
    times >>= 1LL;
  }
  return res;
}
struct cmp {
  bool operator()(const long long& x, const long long& y) { return x > y; }
};
int main() {
  scanf("%d%d", &n, &x);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", a + i);
    sum += a[i];
  }
  priority_queue<long long, vector<long long>, cmp> q;
  for (int i = 1; i <= n; i++) {
    q.push(sum - a[i]);
  }
  long long t;
  while (!q.empty()) {
    t = q.top();
    int cnt = 0;
    while (!q.empty() && (q.top() == t)) {
      cnt++;
      q.pop();
      if (cnt == x) break;
    }
    if (cnt == x)
      q.push(t + 1);
    else
      break;
  }
  t = min(t, sum);
  long long ans = Pow(x, t);
  printf("%I64d\n", ans);
  return 0;
}
