#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)1e18 + 10;
multiset<long long int> ms;
long long int a[300005];
long long int powmod(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = (res * x) % 1000000007;
    x = (x * x) % 1000000007;
    n /= 2;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, g, sum = 0, ma = 0;
  cin >> n >> g;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    ma = max(a[i], ma);
  }
  long long int ans = sum - ma;
  for (long long int i = 1; i <= n; i++) ms.insert(sum - a[i]);
  while (1) {
    long long int x = *ms.begin();
    ms.erase(ms.begin());
    long long int cnt = 1;
    if (x == sum) break;
    while (ms.size() > 0) {
      long long int y = *ms.begin();
      if (y == x)
        ms.erase(ms.begin()), cnt++;
      else
        break;
    }
    if (cnt % g == 0) {
      while (cnt / g > 0) {
        ms.insert(x + 1);
        cnt -= g;
      }
      ans += 1;
    } else {
      cout << powmod(g, ans) << "\n";
      return 0;
    }
  }
  cout << powmod(g, ans) << "\n";
}
