#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[100010];
int main() {
  int n;
  long long x;
  map<long long, int> mp;
  scanf("%d%I64d", &n, &x);
  long long S = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    S += a[i];
  }
  for (int i = 1; i <= n; i++) {
    mp[S - a[i]]++;
  }
  long long b = -1;
  while (1) {
    long long val = mp.begin()->first;
    ;
    int ti = mp.begin()->second;
    if (ti % x == 0) {
      mp[val + 1] += ti / x;
      mp.erase(mp.begin());
    } else {
      b = val;
      break;
    }
  }
  long long ans = 1;
  if (b > S) b = S;
  while (b > 0) {
    if (b & 1) ans = ans * x % mod;
    x = x * x % mod;
    b >>= 1;
  }
  printf("%I64d\n", ans);
  return 0;
}
