#include <bits/stdc++.h>
using namespace std;
void io() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
}
priority_queue<int, vector<int>, std::greater<int> > pn;
priority_queue<int> pm;
bool deb = false;
const int N = 100011;
vector<long long int> a;
long long int pow_mod(long long int a, long long int x) {
  long long int t = 1, y = a % 1000000007;
  while (x > 0) {
    if (x & 1) t = (t * y) % 1000000007;
    x >>= 1;
    y = (y * y) % 1000000007;
  }
  return t;
}
int main() {
  long long int i, j, n, x;
  scanf("%lld", &n), scanf("%lld", &x);
  int fl = 0;
  long long int sm = 0;
  for (i = 0; i < n; i++) scanf("%lld", &j), a.push_back(j), sm += a[i];
  for (i = 0; i < n; i++) a[i] = sm - a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  while (1) {
    long long int ct = 0, mn = a[a.size() - 1];
    n = a.size();
    for (i = n - 1; i > -1; i--) {
      if (a[i] == mn)
        ct++, a.pop_back();
      else
        break;
    }
    if (ct % x != 0) {
      mn = min(mn, sm);
      cout << pow_mod(x, mn) << endl;
      return 0;
    }
    for (i = 0; i < ct / x; i++) a.push_back(mn + 1);
  }
  return 0;
}
