#include <bits/stdc++.h>
using namespace std;
long long modp(long long a, long long m, long long n) {
  n = n % (m - 1);
  a = a % m;
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = (res * a) % m;
    a = (a * a) % m;
    n >>= 1;
  }
  return res;
}
long long modInverse(long long n, long long p) { return modp(n, p, p - 2); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, x, i, sum = 0;
  cin >> n >> x;
  vector<long long> v(n);
  for (i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  sort(v.begin(), v.end());
  sum -= v[n - 1];
  long long ans = modp(x, 1000000007, sum);
  long long l = v[n - 1];
  for (i = 0; i < n; i++) {
    v[i] = l - v[i];
  }
  sort(v.begin(), v.end());
  map<long long, long long> m;
  for (i = 0; i < n; i++) {
    long long count = 0;
    long long t = v[i];
    while (i < n && v[i] == t) {
      count++;
      i++;
    }
    i--;
    while (1) {
      long long r = 0;
      while (count % x == 0) {
        r++;
        count /= x;
      }
      t += r;
      m[t] += count;
      if (m[t] % x == 0) {
        count = m[t];
        m.erase(t);
      } else
        break;
    }
  }
  auto it = m.begin();
  ans *= modp(x, 1000000007, min(l, it->first));
  ans %= 1000000007;
  cout << ans;
}
