#include <bits/stdc++.h>
using namespace std;
const long double PI = 2 * acos(0.0);
void print(vector<bool> &a) {
  for (bool i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<int> &a) {
  for (int i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<char> &a) {
  for (char i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<long long> &a) {
  for (long long i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<vector<int> > &a) {
  for (vector<int> i : a) {
    print(i);
  }
  cout << "\n";
}
void print(vector<vector<long long> > &a) {
  for (vector<long long> i : a) {
    print(i);
  }
  cout << "\n";
}
void print(vector<double> &a) {
  for (double i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<long double> &a) {
  for (long double i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<pair<long long, long long> > &a) {
  for (pair<long long, long long> i : a) {
    cout << i.first << " " << i.second << "\n";
  }
  cout << "\n";
}
void print(deque<pair<long long, long long> > &a) {
  for (pair<long long, long long> i : a) {
    cout << i.first << " " << i.second << "\n";
  }
  cout << "\n";
}
long long dist_sq(pair<long long, long long> a, pair<long long, long long> b) {
  return ((a.first - b.first) * (a.first - b.first) +
          (a.second - b.second) * (a.second - b.second));
}
long long po(long long a, long long b) {
  if (b <= 0)
    return 1;
  else if (b == 1)
    return a;
  long long vl = po((a * a), b / 2);
  if (b % 2 == 0)
    return vl;
  else
    return (vl)*a;
}
long long pomod(long long a, long long b) {
  a = a % 1000000007LL;
  if (b <= 0)
    return 1 % 1000000007LL;
  else if (b == 1)
    return a % 1000000007LL;
  long long vl = pomod((a * a) % 1000000007LL, b / 2);
  vl = vl % 1000000007LL;
  if (b % 2 == 0)
    return vl;
  else
    return ((vl)*a) % 1000000007LL;
}
long long pomod(long long a, long long b, long long mo) {
  a = a % mo;
  if (b <= 0)
    return 1 % mo;
  else if (b == 1)
    return a % mo;
  long long vl = pomod((a * a) % mo, b / 2);
  vl = vl % mo;
  if (b % 2 == 0)
    return vl;
  else
    return ((vl)*a) % mo;
}
long long factmod(long long n, long long mo) {
  long long val = n;
  long long ans = 1;
  while (val >= 1) {
    ans = (ans * val) % 1000000007LL;
    val--;
  }
  return ans;
}
long long inv(long long a, long long mo) { return pomod(a, mo - 2, mo); }
long long floorlog2(long long n) {
  long long h = 0;
  long long p = 1;
  while (p <= n) {
    h++;
    p *= 2;
  }
  return h - 1;
}
long long floorlog2(long long n, long long b) {
  long long h = 0;
  long long p = 1;
  while (p <= n) {
    h++;
    p *= b;
  }
  return h - 1;
}
struct trie {
  long long occ = 0;
  trie *ch[2];
};
struct trie *new_trie() {
  trie *root = new trie;
  root->occ = 1;
  root->ch[0] = NULL;
  root->ch[1] = NULL;
  return root;
}
long long bit_to_ll(const string &bits) {
  int ln = bits.length();
  long long p = 1;
  long long ans = 0;
  for (long long i = (ln - 1); i >= (0); i--) {
    if (bits[i] == '1') {
      ans += p;
    }
    p *= 2;
  }
  return ans;
}
string ll_to_bit(const long long &el) {
  string ans = "";
  long long tmp = el;
  while (tmp != 0) {
    int d = tmp % 2;
    if (d) {
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }
    tmp /= 2;
  }
  int ln = ans.length();
  while (ans.length() != 33) {
    ans = "0" + ans;
  }
  return ans;
}
void insert(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[0] == NULL) {
        temp->ch[0] = new_trie();
      } else {
        temp->ch[0]->occ++;
      }
      temp = temp->ch[0];
    } else {
      if (temp->ch[1] == NULL) {
        temp->ch[1] = new_trie();
      } else {
        temp->ch[1]->occ++;
      }
      temp = temp->ch[1];
    }
  }
}
void del(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[0] == NULL) {
        return;
      } else {
        temp->ch[0]->occ--;
      }
      temp = temp->ch[0];
    } else {
      if (temp->ch[1] == NULL) {
        return;
      } else {
        temp->ch[1]->occ--;
      }
      temp = temp->ch[1];
    }
  }
}
long long maxxor(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  long long mx = el;
  string maxstring = "";
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[1] == NULL || temp->ch[1]->occ == 0) {
        maxstring = maxstring + "0";
        temp = temp->ch[0];
      } else {
        maxstring = maxstring + "1";
        temp = temp->ch[1];
      }
    } else {
      if (temp->ch[0] == NULL || temp->ch[0]->occ == 0) {
        maxstring = maxstring + "0";
        temp = temp->ch[1];
      } else {
        maxstring = maxstring + "1";
        temp = temp->ch[0];
      }
    }
  }
  return bit_to_ll(maxstring);
}
void del_trie(trie *root) {
  if (root->ch[1] != NULL) {
    del_trie(root->ch[1]);
  }
  if (root->ch[0] != NULL) {
    del_trie(root->ch[0]);
  }
  delete root;
}
vector<vector<int> > dist(105, vector<int>(105, 0));
vector<vector<bool> > seen(105, vector<bool>(105, 0));
vector<vector<pair<int, int> > > par(105,
                                     vector<pair<int, int> >(105,
                                                             make_pair(0, 0)));
long long compute_exp(vector<long long> &a, long long n, long long first) {
  long long cur_deg = a[0];
  long long cnt = 1;
  int i = 1;
  while (i < a.size()) {
    if (a[i] == cur_deg) {
      cnt++;
      i += 1;
    } else {
      while (a[i] != cur_deg and cnt % first == 0) {
        cnt /= first;
        cur_deg += 1;
      }
      if (a[i] != cur_deg) return cur_deg;
    }
  }
  while (cnt % first == 0) {
    cnt /= first;
    cur_deg += 1;
  }
  return cur_deg;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  long long n, first;
  cin >> n >> first;
  vector<long long> a(n, 0);
  long long sum = 0;
  for (long long i = (0); i <= (n - 1); i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (long long i = (0); i <= (n - 1); i++) {
    a[i] = sum - a[i];
  }
  sort(a.begin(), a.end());
  long long n_exp = compute_exp(a, n, first);
  long long f_exp = min(sum, n_exp);
  cout << pomod(first, f_exp);
  return 0;
}
