#include <bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
long long a[N], b[N];
struct node {
  long long v;
  int cn;
} c[N];
long long fun(long long x, long long b) {
  b %= 1000000007 - 1;
  long long ans = 1, t = x;
  while (b) {
    if (b & 1) ans = (ans * t) % 1000000007;
    b >>= 1;
    t = (t * t) % 1000000007;
  }
  return ans;
}
int main() {
  int n;
  long long x, sum = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  for (int i = 0; i < n; i++) b[i] = sum - a[i];
  sort(b, b + n);
  long long te = -1;
  c[0].v = -1;
  int mj = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] != c[mj].v) {
      mj++;
      c[mj].v = b[i];
      c[mj].cn = 1;
    } else
      c[mj].cn++;
  }
  if (mj == 1) {
    while (c[1].cn % x == 0) {
      c[1].v++;
      c[1].cn /= x;
    }
    te = c[1].v;
  } else {
    for (int i = 1; i < mj; i++) {
      while (c[i].v < c[i + 1].v) {
        if (c[i].cn % x != 0) {
          te = c[i].v;
          break;
        } else {
          c[i].v++;
          c[i].cn /= x;
        }
      }
      if (te != -1) break;
      c[i + 1].cn += c[i].cn;
    }
    if (te == -1) {
      while (c[mj].cn % x == 0) {
        c[mj].cn /= x;
        c[mj].v++;
      }
      te = c[mj].v;
    }
  }
  printf("%lld\n", fun(x, min(te, sum)));
  return 0;
}
