#include <bits/stdc++.h>
using namespace std;
unsigned long long re(unsigned long long a, unsigned long long b) {
  if (b == 0) return 1;
  if (b % 2)
    return (re(a, b - 1) * a) % 1000000007;
  else
    return re((a * a) % 1000000007, b / 2);
}
int main() {
  unsigned long long n, x;
  cin >> n >> x;
  vector<unsigned long long> arr;
  unsigned long long sum = 0;
  unsigned long long powa = 0;
  for (int i = 0; i < n; i++) {
    unsigned long long v;
    cin >> v;
    sum += v;
    arr.push_back(v);
  }
  for (int i = 0; i < n; i++) {
    arr[i] = (sum - arr[i]);
  }
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  int coun = 0;
  for (int i = arr.size() - 1; i >= 0; i--) {
    if (arr[i] != arr[i - 1]) {
      coun++;
      int k = coun;
      unsigned long long l = arr[i];
      if (coun % x == 0 && coun > 0) {
        while (k--) {
          arr.pop_back();
        }
        coun /= x;
        while (coun--) {
          arr.push_back(l + 1);
        }
        i = arr.size();
        powa = arr[i];
        coun = 0;
      } else {
        powa = arr[i];
        break;
      }
    } else {
      coun++;
    }
  }
  unsigned long long ans = 1;
  powa = min(powa, sum);
  ans = re(x, powa);
  cout << ans << endl;
  return 0;
}
