#include <bits/stdc++.h>
using namespace std;
long long a[100000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  for (int i = 0; i < n; i++) a[i] = sum - a[i];
  sort(a, a + n);
  stack<pair<long long, long long> > s;
  for (int i = n - 1; i >= 0; i--) s.push(make_pair(a[i], 1));
  long long ans;
  long long k;
  while (!s.empty() && ans < sum) {
    ans = (s.top()).first;
    k = 0;
    while (!s.empty() && (s.top()).first == ans) {
      k += (s.top()).second;
      s.pop();
    }
    if (k % x == 0) {
      s.push(make_pair(ans + 1, k / x));
    } else
      break;
  }
  long long mul = x;
  long long ans1 = 1;
  while (ans != 0) {
    if (ans % 2 == 1) ans1 = (ans1 * mul) % (long long)(1e9 + 7);
    mul = (mul * mul) % (long long)(1e9 + 7);
    ans /= 2;
  }
  cout << ans1 << endl;
  return 0;
}
