#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll M = 1000000007;
const ll N = 998244353;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll inv(ll x, ll m) { return power(x, m - 2, m); }
ll nCr(ll n, ll r, vector<ll> &fac) {
  if (r == 0) return 1;
  return (fac[n] * inv(fac[r], M) % M * inv(fac[n - r], M) % M) % M;
}
struct comp {
  template <typename T>
  bool operator()(const T &a, const T &b) {
    if (a.first == b.first)
      return (a.second < b.second);
    else
      return (a.first < b.first);
  }
};
bool mod(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first < b.first);
}
void sieve(ll mn, ll mx, vector<ll> &primes) {
  vector<bool> pr(10000000 + 1, true);
  for (ll i = 2; i * i <= 10000000; i++)
    if (pr[i] == true)
      for (ll j = i * i; j <= 10000000; j += i) pr[j] = false;
  for (int i = 2; i <= 100000; i++)
    if (pr[i]) primes.push_back(i);
}
bool isValid(ll i, ll j, ll n, ll m) {
  if (i >= 0 && i < n && j >= 0 && j < m) {
    return true;
  }
  return false;
}
void dfs(ll v, ll p, vector<vector<ll> > &adj, vector<bool> &vis) {
  vis[v] = true;
  for (int i = 0; i < (ll)((adj[v]).size()); i++) {
    if (!vis[adj[v][i]]) {
      dfs(adj[v][i], v, adj, vis);
    }
  }
}
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
void dfs1(pair<ll, ll> st, int d, vector<vector<ll> > &mat, vector<string> &v,
          ll n, ll m, int &cycle, int &num, vector<vector<bool> > &vis,
          vector<vector<bool> > &done) {
  cout << st.first << " " << st.second << "\n";
  num = max(num, d);
  vis[st.first][st.second] = true;
  for (int i = 0; i < 4; i++) {
    int x = st.first + dx[i];
    int y = st.second + dy[i];
    int a = v[st.first][st.second] - 'A';
    int b = v[x][y] - 'A';
    if (isValid(x, y, n, m) && mat[a][b] == 1) {
      if (!vis[x][y]) {
        if (cycle == 1) {
          return;
        }
        dfs1({x, y}, d + 1, mat, v, n, m, cycle, num, vis, done);
      } else {
        if (done[x][y] == false) {
          cycle = 1;
          return;
        }
      }
    }
  }
  done[st.first][st.second] = true;
}
void makeSet(vector<ll> &parent, vector<ll> &size, ll v) {
  parent[v] = v;
  size[v] = 1;
}
ll findSet(ll v, vector<ll> &parent) {
  if (parent[v] == v) {
    return v;
  }
  return parent[v] = findSet(parent[v], parent);
}
void unionSet(vector<ll> &parent, vector<ll> &size, ll u, ll v) {
  ll pU = findSet(u, parent);
  ll pV = findSet(v, parent);
  if (pU != pV) {
    if (size[pU] <= size[pV]) {
      parent[pU] = pV;
      size[pV] += size[pU];
    } else {
      parent[pV] = pU;
      size[pU] += size[pV];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vector<int> arr(n);
  ll sum = 0LL;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += 1LL * arr[i];
  }
  map<ll, int> cnt;
  for (int i = 0; i < n; ++i) {
    ++cnt[sum - arr[i]];
  }
  ll val;
  auto it = cnt.begin();
  while (true) {
    if (it->second % x) {
      val = it->first;
      break;
    }
    cnt[it->first + 1] += (it->second / x);
    ++it;
  }
  val = min(val, sum);
  vector<ll> lg2(64);
  lg2[0] = x;
  for (int i = 1; i < 64; ++i) {
    lg2[i] = (lg2[i - 1] * lg2[i - 1]) % M;
  }
  ll sol = 1LL;
  while (val) {
    ll lg = ll(log2(val));
    val -= (1LL << lg);
    sol = (sol * lg2[lg]) % M;
  }
  cout << sol;
  return 0;
  return 0;
}
