#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, X;
long long xp[21];
long long A[100001];
const long long MOD = 1000000007;
long long mod_pow(long long x, long long n, long long mod) {
  if (n == 0) return 1;
  long long ret = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) ret = ret * x % mod;
  return ret;
}
int main() {
  scanf("%d %d", &N, &X);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  xp[0] = 1;
  for (int i = 0; i < 20; i++) {
    if (xp[i] == -1) {
      xp[i + 1] = -1;
    } else {
      xp[i + 1] = xp[i] * X;
      if (xp[i + 1] > N) xp[i + 1] = -1;
    }
  }
  long long s = 0;
  for (int i = 0; i < N; i++) {
    s += A[i];
  }
  for (int i = 0; i < N; i++) {
    A[i] = s - A[i];
  }
  sort(A, A + N);
  long long y;
  y = A[0];
  for (int i = 0; i < N; i++) {
    A[i] -= y;
  }
  long long x;
  x = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] <= 20 && xp[A[i]] >= 0) {
      x += xp[A[i]];
    }
  }
  while (x > 0 && (x % X) == 0) {
    y++;
    x /= X;
  }
  y = min(y, s);
  cout << mod_pow(X, y, MOD) << endl;
  return 0;
}
