use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let h: i64 = itr.next().unwrap().parse().unwrap();
        let c: i64 = itr.next().unwrap().parse().unwrap();
        let t: i64 = itr.next().unwrap().parse().unwrap();
        if t == h {
            writeln!(out, "1").ok();
        } else if t <= (h + c) / 2 {
            writeln!(out, "2").ok();
        } else {
            // a_i = ((h + c) * (i - 1) + h) / (i * 2 - 1)

            let mut l = 1;
            let mut r = 1000000;
            while r - l > 1 {
                let mid = (l + r) >> 1;

                // (h + c) * (i - 1) + h > t * (x * 2 - 1)
                if (h + c) * (mid - 1) + h > t * (mid * 2 - 1) {
                    l = mid;
                } else {
                    r = mid;
                }
            }

            // ((h + c) * (l - 1) + h) / (l*2-1) - t > t - ((h + c) * (r - 1) + h) / (r*2-1)
            if ((h + c) * (l - 1) + h) * (r * 2 - 1) + ((h + c) * (r - 1) + h) * (l * 2 - 1)
                > 2 * t * (l * 2 - 1) * (r * 2 - 1)
            {
                writeln!(out, "{}", r * 2 - 1).ok();
            } else {
                writeln!(out, "{}", l * 2 - 1).ok();
            }
        }
    }
    stdout().write_all(&out).unwrap();
}


use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let h: i64 = itr.next().unwrap().parse().unwrap();
        let c: i64 = itr.next().unwrap().parse().unwrap();
        let t: i64 = itr.next().unwrap().parse().unwrap();
        if t >= h {
            writeln!(out, "1").ok();
        } else if t <= (h + c) / 2 {
            writeln!(out, "2").ok();
        } else {
            // a_i = ((h + c) * (i - 1) + h) / (i * 2 - 1)

            let mut l = 0;
            let mut r = 1000000;
            while r - l > 1 {
                let mid = (l + r) >> 1;

                // (h + c) * (i - 1) + h > t * (x * 2 - 1)
                if (h + c) * mid + h > t * (mid * 2 + 1) {
                    l = mid;
                } else {
                    r = mid;
                }
            }

            if (h + c) * l + h - t * (l * 2 + 1) > (h + c) * r + h - t * (r * 2 + 1) {
                writeln!(out, "{}", r + r + 1).ok();
            } else {
                writeln!(out, "{}", l + l + 1).ok();
            }
        }
    }
    stdout().write_all(&out).unwrap();
}


use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let h: i64 = itr.next().unwrap().parse().unwrap();
        let c: i64 = itr.next().unwrap().parse().unwrap();
        let t: i64 = itr.next().unwrap().parse().unwrap();
        if t == h {
            writeln!(out, "1").ok();
        } else if t <= (h + c) / 2 {
            writeln!(out, "2").ok();
        } else {
            // a_i = ((h + c) * (i - 1) + h) / (i * 2 - 1)

            let mut l = 1;
            let mut r = 1000000;
            while r - l > 1 {
                let mid = (l + r) >> 1;

                // (h + c) * (i - 1) + h > t * (x * 2 - 1)
                if (h + c) * (mid - 1) + h > t * (mid * 2 - 1) {
                    l = mid;
                } else {
                    r = mid;
                }
            }

            // t - ((h + c) * (l - 1) + h) / (l*2-1) > ((h + c) * (r - 1) + h) / (r*2-1) - t
            if ((h + c) * (l - 1) + h) * (r * 2 - 1) - ((h + c) * (r - 1) + h) * (l * 2 - 1)
                + 2 * t * (l * 2 - 1) * (r * 2 - 1)
                > 0
            {
                writeln!(out, "{}", r * 2 - 1).ok();
            } else {
                writeln!(out, "{}", l * 2 - 1).ok();
            }
        }
    }
    stdout().write_all(&out).unwrap();
}


#include <iostream>
#include <map>
using namespace std;

typedef long long LLL;
const LLL P = 1000000007;

int n, x, a;
map<int, int, greater<int> > cnt;
long long sum;

long long pow(LLL a, LLL n) {
	if (n == 0) return 1;
	LLL res = pow(a, n / 2);
	res = res * res % P;
	if (n % 2 == 1) res = res * a % P;
	return res;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif

	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		cnt[a]++;
	}
	while (1) {
		if (cnt.begin()->first == 0) break;
		if (cnt.begin()->second % x == 0) {
			cnt[cnt.begin()->first - 1] += cnt.begin()->second / x;
			cnt.erase(cnt.begin());
		} else {
			break;
		}
	}
	sum -= cnt.begin()->first;
	cout << pow(x, sum);

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const long long MAX_N = 1000005LL;
const long long INF = 1000000000000000000LL;
const long long MOD = 1000000007LL;

long long a[MAX_N];

long long vozved(long long x, long long step)
{
	long long a = (x % MOD);
	long long b = 1;
	long long y = step;
	while (y > 0)
	{
		if ((y % 2) != 0) b = ((b % MOD) * (a % MOD)) % MOD;
		a = ((a % MOD) * (a % MOD)) % MOD;
		y /= 2LL;
	}
	return b;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n, x;
	cin >> n >> x;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	long long min_step = INF;
	for (int i = 0; i < n; i++)
		min_step = min(min_step, sum - a[i]);

	int f = 1;
	for (int i = 0; i < n; i++)
	{
		long long step = sum - a[i];
		if (step != min_step)
		{
			f = 0;
			break;
		}
	}

	long long ans = 1;
	long long w = vozved(x, min(sum, min_step));
	sum -= min(sum, min_step);
	ans = (w % MOD);

	if (f)
	{
		while ((n % x) == 0 && sum > 0)
		{
			ans = ((ans % MOD) * (x % MOD)) % MOD;
			n /= x;
			sum--;
		}
	}

	cout << (ans % MOD);

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const long long MAX_N = 1000005LL;
const long long INF = 1000000000000000000LL;
const long long MOD = 1000000007LL;

long long a[MAX_N];

long long vozved(long long x, long long step)
{
	long long a = (x % MOD);
	long long b = 1;
	long long y = step;
	while (y > 0)
	{
		if ((y % 2) != 0) b = ((b % MOD) * (a % MOD)) % MOD;
		a = ((a % MOD) * (a % MOD)) % MOD;
		y /= 2LL;
	}
	return b;
}

long long ev(long long a, long long b)
{
	while (a && b)
		a > b ? a %= b : b %= a;
	return (a + b) % MOD;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n, x;
	cin >> n >> x;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	long long all_sum = sum;

	long long min_step = INF;
	for (int i = 0; i < n; i++)
		min_step = min(min_step, sum - a[i]);

	int f = 1;
	for (int i = 0; i < n; i++)
	{
		long long step = sum - a[i];
		if (step != min_step)
		{
			f = 0;
			break;
		}
	}

	long long ans = 1;
	long long w = vozved(x, min(sum, min_step));
	sum -= min(sum, min_step);
	ans = (w % MOD);

	if (f)
	{
		while ((n % x) == 0 && sum > 0)
		{
			ans = ((ans % MOD) * (x % MOD)) % MOD;
			n /= x;
			sum--;
		}
	}
	else
	{
		long long chisl = 0;
		long long znam = 1;
		znam = vozved(x, sum);
		for (int i = 0; i < n; i++)
		{
			long long d = vozved(x, all_sum - min_step - a[i]);
			chisl = (chisl + d) % MOD;
		}
		long long q = ev(chisl, znam);
		ans = (ans * q) % MOD;
	}

	cout << (ans % MOD);

	return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX_N = 100005;
const long long MOD = 1000000007LL;

long long a[MAX_N];
vector<long long> q;

long long vozved(long long x, long long step)
{
	long long a = x;
	long long b = 1;
	long long y = step;
	while (y > 0)
	{
		if (y % 2 != 0)
			b = (b * a) % MOD;
		a = (a * a) % MOD;
		y /= 2LL;
	}
	return b;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n, x;
	cin >> n >> x;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	for (int i = 0; i < n; i++)
		q.push_back(sum - a[i]);
	sort(q.begin(), q.end());
	reverse(q.begin(), q.end());

	long long min_step = 0;
	while (1)
	{
		long long v = q[(int)q.size() - 1];
		long long cnt = 0;
		while ((int)q.size() > 0 && q[(int)q.size() - 1] == v)
		{
			cnt++;
			q.pop_back();
		}

		if (cnt % x == 0)
		{
			cnt /= x;
			for (int i = 0; i < cnt; i++)
				q.push_back(v + 1);
		}
		else
		{
			min_step = min(v, sum);
			long long ans = vozved(x, min_step);
			cout << ans;
			return 0;
		}
	}

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const int MAX_N = 100005;
const long long INF = 1000000000000000000LL;
const long long MOD = 1000000007LL;

long long a[MAX_N];

long long vozved(long long x, long long step)
{
	long long a = x;
	long long b = 1;
	long long y = step;
	while (y > 0)
	{
		if (y % 2 != 0) b = (b * a) % MOD;
		a = (a * a) % MOD;
		y /= 2;
	}
	return b;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n, x;
	cin >> n >> x;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	long long min_step = INF;
	for (int i = 0; i < n; i++)
		min_step = min(min_step, sum - a[i]);

	int f = 1;
	for (int i = 0; i < n; i++)
	{
		long long step = sum - a[i];
		if (step != min_step)
		{
			f = 0;
			break;
		}
	}

	long long ans = 1;
	long long w = vozved(x, min_step);
	sum -= min_step;
	ans = w;

	if (f)
	{
		while (n % x == 0 && sum > 0)
		{
			ans = (ans * x) % MOD;
			n /= x;
			sum--;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#pragma warning(disable:4996)

#define MOD 1000000007

int n,x;
int d[100010];
long long e[100010],sum,r;

int power() {
	long long res=1, pre=x;
	while (r) {
		if (r%2==1)	res*=pre; res%=MOD;
		pre*=pre; pre%=MOD;
		r/=2;
	}
	return (int)res;
}

int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","rt",stdin);
		//freopen("output.txt","wt",stdout);
	#endif

	scanf("%d%d",&n,&x);
	for (int i=0; i<n; i++) {
		scanf("%d",&d[i]);
		sum+=d[i];
	};

	for (int i=0; i<n; i++)
		e[i]=sum-d[i];

	sort(e,e+n);

	int p1=0,p2=0; e[n]=-1;
	while (p1<n) {
		while (e[p1]==e[p2]) p2++;
		p2--;

		if ((p2-p1+1)%x!=0) { r = e[p1]; break; }

		for (int i=0; i<(p2-p1+1)/x; i++)
			e[p2-i]=e[p1]+1;
		p1 = p2-(p2-p1+1)/x+1; p2=p1;
	}

	r = min(r,sum);
	cout<< power() <<endl;
	return 0;
};


#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#pragma warning(disable:4996)

#define MOD 1000000007

int n,x;
int d[100010];
long long e[100010],sum,r;

int power() {
	long long res=1, pre=x;
	while (r) {
		if (r%2==1)	res*=pre; res%=MOD;
		pre*=pre; pre%=MOD;
		r/=2;
	}
	return (int)res;
}

int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","rt",stdin);
		//freopen("output.txt","wt",stdout);
	#endif

	scanf("%d%d",&n,&x);
	for (int i=0; i<n; i++) {
		scanf("%d",&d[i]);
		sum+=d[i];
	};

	for (int i=0; i<n; i++)
		e[i]=sum-d[i];

	sort(e,e+n);

	int p1=0,p2=0; e[n]=-1;
	while (p1<n) {
		while (e[p1]==e[p2]) p2++;
		p2--;

		if ((p2-p1+1)%x!=0) { r = e[p1]; break; }

		for (int i=0; i<(p2-p1+1)/x; i++)
			e[p2-i]=e[p1]+1;
		p1 = p2-(p2-p1+1)/x+1; p2=p1;
	}

	cout<< power() <<endl;
	return 0;
};


#include <cstdio>
#include <algorithm>

const int MAX_N = 100000 + 10;
const int MOD = 1000000007;

typedef __int64 ll;

ll min(const ll a, const ll b) {
	return (a < b) ? a : b;
}

ll pow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y % 2) {
			ans = ans * x % MOD;
		}
		y /= 2;
		x = x * x % MOD;
	}
	return ans;
}

int N = 0;
ll x = 0;
ll a[MAX_N] = {0, };
ll s[MAX_N] = {0, };

int main() {
	scanf("%d%I64d", &N, &x);
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%I64d", a + i);
		sum += a[i];
	}
	for (int i = 0; i < N; ++i) {
		s[i] = sum - a[i];
	}
	std::sort(s, s + N);
	ll y = s[0];
	int cnt = 1;
	for (int i = 1; i < N; ++i) {
		if (y == s[i]) {
			++cnt;
			if (N - 1 != i) {
				continue;
			}
		}

		if (cnt % x) {
			printf("%I64d\n", pow(x, min(y, sum)));
			return 0;
		}

		cnt /= x;
		++y;
		for (int j = 0; j < cnt; ++j) {
			s[i--] = y;
		}
		cnt = 0;
	}
	printf("%I64d\n", pow(x, y));
	return 0;
}


#include <cstdio>
#include <algorithm>

const int MAX_N = 100000 + 10;
const int MOD = 1000000007;

typedef __int64 ll;

ll min(const ll a, const ll b) {
	return (a < b) ? a : b;
}

ll pow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y % 2) {
			ans = ans * x % MOD;
		}
		y /= 2;
		x = x * x % MOD;
	}
	return ans;
}

int N = 0;
ll x = 0;
ll a[MAX_N] = {0, };
ll s[MAX_N] = {0, };

int main() {
	scanf("%d%I64d", &N, &x);
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%I64d", a + i);
		sum += a[i];
	}
	for (int i = 0; i < N; ++i) {
		s[i] = sum - a[i];
	}
	std::sort(s, s + N);
	ll y = s[0];
	int cnt = 1;
	for (int i = 1; i < N; ++i) {
		if (y == s[i]) {
			++cnt;
			if (N - 1 != i) {
				continue;
			}
		}

		if (cnt % x) {
			printf("%I64d\n", pow(x, min(y, sum)));
			return 0;
		}

		cnt /= x;
		++y;
		for (int j = 0; j < cnt; ++j) {
			s[--i] = y;
		}
		--i;
		cnt = 0;
	}
	printf("%I64d\n", pow(x, y));
	return 0;
}


#include <cstdio>
#include <algorithm>

const int MAX_N = 100000 + 10;
const int MOD = 1000000007;

typedef __int64 ll;

ll pow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y % 2) {
			ans = ans * x % MOD;
		}
		y /= 2;
		x = x * x % MOD;
	}
	return ans;
}

int N = 0;
ll x = 0;
ll a[MAX_N] = {0, };
ll s[MAX_N] = {0, };

int main() {
	scanf("%d%I64d", &N, &x);
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%I64d", a + i);
		sum += a[i];
	}
	for (int i = 0; i < N; ++i) {
		s[i] = sum - a[i];
	}
	std::sort(s, s + N);
	ll y = s[0];
	int cnt = 1;
	for (int i = 1; i < N; ++i) {
		if (y == s[i]) {
			++cnt;
			if (N - 1 != i) {
				continue;
			}
		}

		if (cnt % x) {
			printf("%I64d\n", pow(x, y));
			return 0;
		}

		cnt /= x;
		++y;
		for (int j = 0; j < cnt; ++j) {
			s[i--] = y;
		}
		cnt = 0;
	}
	printf("%I64d\n", pow(x, y));
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cctype>
#include <list>
#include <sstream>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
#define X first
#define Y second
#define mp make_+pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
const int inf=1e9+7;
const long long linf=1e18;
typedef long double lf;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long double,long double> pdd;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
#define sqr(a) ((a)*(a))
ll a[1000005],sum;
ll fastpow(ll x,ll y){
	ll temp=x,ans=1;
	while (y){
		if (y&1) ans=ans*temp%inf;
		temp=temp*temp%inf;
		y=y>>1;
	}
	return ans;
}
map<ll,int> f;
int main(){
	ios::sync_with_stdio(false);
	int n,x;cin>>n>>x;
	for (int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
	ll ans=linf;
	for (int i=1;i<=n;i++) ans=min(ans,sum-a[i]);
	f.clear();
	for (int i=1;i<=n;i++) a[i]=sum-a[i],f[a[i]]++;
	while (f[ans]%x==0){
		f[ans+1]+=f[ans]/x;
		ans++;
	}
	ans=min(ans,sum);
	cout<<fastpow(x,ans)<<endl;
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cctype>
#include <list>
#include <sstream>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
#define X first
#define Y second
#define mp make_+pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
const int inf=1e9+7;
const long long linf=1e18;
typedef long double lf;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long double,long double> pdd;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
#define sqr(a) ((a)*(a))
ll a[1000005],sum;
ll fastpow(int x,int y){
	int temp=x,ans=1;
	while (y){
		if (y&1) ans=ans*temp%inf;
		temp=temp*temp%inf;
		y=y>>1;
	}
	return ans;
}
map<ll,int> f;
int main(){
	ios::sync_with_stdio(false);
	int n,x;cin>>n>>x;
	for (int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
	f.clear();
	for (int i=1;i<=n;i++) a[i]=sum-a[i],f[a[i]]++;
	ll cur=f.begin()->X;
	while (f[cur]%x==0){
		f[cur+1]+=f[cur]/x;
		cur++;
	}
	cur=min(cur,sum);
	cout<<fastpow(x,cur)<<endl;
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cctype>
#include <list>
#include <sstream>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
#define X first
#define Y second
#define mp make_+pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
const int inf=1e9+7;
const long long linf=1e18;
typedef long double lf;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long double,long double> pdd;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
#define sqr(a) ((a)*(a))
ll a[1000005],sum;
ll fastpow(int x,int y){
	int temp=x,ans=1;
	while (y){
		if (y&1) ans=ans*temp%inf;
		temp=temp*temp%inf;
		y=y>>1;
	}
	return ans;
}
map<ll,int> f;
int main(){
	ios::sync_with_stdio(false);
	int n,x;cin>>n>>x;
	for (int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
	ll ans=linf;
	for (int i=1;i<=n;i++) ans=min(ans,sum-a[i]);
	f.clear();
	for (int i=1;i<=n;i++) a[i]=sum-a[i],f[a[i]]++;
	while (f[ans]%x==0){
		f[ans+1]+=f[ans]/x;
		ans++;
	}
	ans=min(ans,sum);
	cout<<fastpow(x,ans)<<endl;
	return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cctype>
#include <list>
#include <sstream>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
#define X first
#define Y second
#define mp make_+pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
const int inf=1e9+7;
const long long linf=1e18;
typedef long double lf;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long double,long double> pdd;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
#define sqr(a) ((a)*(a))
ull a[1000005],sum;
ull fastpow(int x,ull y){
	int temp=x,ans=1;
	while (y){
		if (y&1) ans=ans*temp%inf;
		temp=temp*temp%inf;
		y=y>>1;
	}
	return ans;
}
map<ll,int> f;
int main(){
	ios::sync_with_stdio(false);
	int n,x;cin>>n>>x;
	for (int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
	ull m=linf;
	f.clear();
	for (int i=1;i<=n;i++) a[i]=sum-a[i],f[a[i]]++;
	ull cur=f.begin()->X;
	while (f[cur]%x==0){
		f[cur+1]+=f[cur]/x;
		cur++;
	}
	cur=min(cur,sum);
	cout<<fastpow(x,cur)<<endl;
	return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(arr[idx], next - idx));
			idx = next;
		}

		vector<ll> comb;

		ll least = 1e20;
		UP(i, 0, nodes.size()) {
			if (nodes[i].num % x == 0) {
				comb.push_back(sum - nodes[i].val + nodes[i].num / x);
			} else {
				comb.push_back(sum - nodes[i].val);
			}

			least = min(least, comb.back());
		}

		ll res = 1;
		UP(i, 0, least) {
			res *= x;
			res %= 1000000007;
		}

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(arr[idx], next - idx));
			idx = next;
		}

		vector<ll> comb;

		ll least = 1e20;
		UP(i, 0, nodes.size()) {
			if (nodes[i].num % x == 0) {
				comb.push_back(sum - nodes[i].val + nodes[i].num / x);
			} else {
				comb.push_back(sum - nodes[i].val);
			}

			least = min(least, comb.back());
		}

		ll res = mod_pow(x, least, 1000000007);

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll getCoef(ll x, ll n) {
	ll mul = x;
	ll num = 1;
	while (n % mul == 0) {
		mul *= x;
		num ++;
	}
	return num - 1;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(arr[idx], next - idx));
			idx = next;
		}

		vector<ll> comb;

		ll least = 1e20;
		UP(i, 0, nodes.size()) {
			if (nodes[i].num % x == 0) {
				int coef = getCoef(x, nodes[i].num);
				comb.push_back(sum - nodes[i].val + coef);
			} else {
				comb.push_back(sum - nodes[i].val);
			}

			least = min(least, comb.back());
		}

		ll res = mod_pow(x, least, 1000000007);

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll getCoef(ll x, ll n) {
	ll mul = x;
	ll num = 1;
	while (n % mul == 0) {
		mul *= x;
		num ++;
	}
	return num - 1;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(sum - arr[idx], next - idx));
			idx = next;
		}

		for (idx = nodes.size() - 1; idx > 0; ) {
			if (nodes[idx].num % x != 0) {
				break;
			} else {
				if (nodes[idx - 1].val == nodes[idx].val + 1) {
					nodes[idx - 1].num += nodes[idx].num / x;
					nodes.pop_back();
					idx --;
				} else {
					nodes[idx].num /= x;
					nodes[idx].val ++;
				}
			}
		}

		ll coef = getCoef(x, nodes[idx].num);
		ll least = min(sum, coef + nodes[idx].val);

		ll res = mod_pow(x, least, 1000000007);

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll getCoef(ll x, ll n) {
	ll mul = x;
	ll num = 1;
	while (n % mul == 0) {
		mul *= x;
		num ++;
	}
	return num - 1;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(arr[idx], next - idx));
			idx = next;
		}

		vector<ll> comb;

		ll least = sum;
		UP(i, 0, nodes.size()) {
			if (nodes[i].num % x == 0) {
				int coef = getCoef(x, nodes[i].num);
				comb.push_back(sum - nodes[i].val + coef);
			} else {
				comb.push_back(sum - nodes[i].val);
			}

			least = min(least, comb.back());
		}

		ll res = mod_pow(x, least, 1000000007);

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		map<ll, ll> stat;

		UP(i, 0, n) {
			stat[sum - arr[i]] ++;
		}

		map<ll, ll>::iterator it;
		comb.clear();
		ll  val;

		ll least = 1e20;
		for (it = stat.begin(); it != stat.end(); it ++) {
			if (it->second % x == 0) {
				comb.push_back(it->first + (it->second / x));
			} else {
				comb.push_back(it->first);
			}
			least = min(least, comb.back());
		}

		ll res = 1;
		UP(i, 0, least) {
			res *= x;
			res %= 1000000007;
		}

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		map<ll, ll> stat;

		UP(i, 0, n) {
			if (stat.count(sum - arr[i]) == 0) {
				stat[sum - arr[i]] = 1;
			} else {
				stat[sum - arr[i]] ++;
			}
		}

		map<ll, ll>::iterator it;
		comb.clear();
		ll least = sum, val;
		for (it = stat.begin(); it != stat.end(); it ++) {
			if (it->second % x == 0) {
				comb.push_back(it->first + (it->second / x));
			} else {
				comb.push_back(it->first);
			}
		}

		sort(comb.begin(), comb.end());

		ll res = 1;
		UP(i, 0, comb[0]) {
			res *= x;
			res %= 1000000007;
		}

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	ll val, num;
	Node(ll v, ll n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll getCoef(ll x, ll n) {
	ll mul = x;
	ll num = 1;
	while (n % mul == 0) {
		mul *= x;
		num ++;
	}
	return num - 1;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			ll val = sum - arr[idx];
			nodes.push_back(Node(val, next - idx));
			idx = next;
		}

		for (idx = nodes.size() - 1; idx > 0; ) {
			if (nodes[idx].num % x != 0) {
				break;
			} else {
				if (nodes[idx - 1].val == nodes[idx].val + 1) {
					nodes[idx - 1].num += nodes[idx].num / x;
					nodes.pop_back();
					idx --;
				} else {
					nodes[idx].num /= x;
					nodes[idx].val ++;
				}
			}
		}

		ll coef = getCoef(x, nodes[idx].num);
		ll least = min(sum, coef + nodes[idx].val);

		ll res = mod_pow(x, least, 1000000007);

		printf("%I64d\n", res);
	}
    return 0;
}


#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define CLEAR(a, val) memset(a, val, sizeof(a))
#define UP(i, s, t) for (int i = (s); i < (t); i += 1)
#define DOWN(i, s, t) for (int i = (s); i > (t); i -= 1)

typedef long long ll;
using namespace std;
const int MAXINT = 1 << 31 - 1;
const int MAXN = 100005;

ll n, x;
ll sum;
ll arr[MAXN];
vector<ll> comb;

template <typename T>
T gcd(T a, T b) {
  while (b != 0) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}

class Node {
public:
	int val, num;
	Node(int v, int n) {
		val = v;
		num = n;
	}
};

vector<Node> nodes;

int main () {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	while (scanf("%I64d %I64d", &n, &x) != -1) {
		sum = 0;
		UP(i, 0, n) {
			scanf("%I64d", &arr[i]);
			sum += arr[i];
		}

		sort(arr, arr + n);

		nodes.clear();
		int idx = 0;
		while (idx < n) {
			int next = idx + 1;
			while (next < n && arr[next] == arr[idx]) {
				next ++;
			}
			nodes.push_back(Node(arr[idx], next - idx));
			idx = next;
		}

		vector<ll> comb;

		ll least = 1e20;
		UP(i, 0, nodes.size()) {
			if (nodes[i].num % x == 0) {
				comb.push_back(sum - nodes[i].val + nodes[i].num / x);
			} else {
				comb.push_back(sum - nodes[i].val);
			}

			least = min(least, comb.back());
		}

		/*map<ll, ll> stat;

		UP(i, 0, n) {
			stat[sum - arr[i]] ++;
		}

		map<ll, ll>::iterator it;
		comb.clear();
		ll  val;

		ll least = 1e20;
		for (it = stat.begin(); it != stat.end(); it ++) {
			if (it->second % x == 0) {
				comb.push_back(it->first + (it->second / x));
			} else {
				comb.push_back(it->first);
			}
			least = min(least, comb.back());
		}*/

		ll res = 1;
		UP(i, 0, least) {
			res *= x;
			res %= 1000000007;
		}

		printf("%I64d\n", res);
	}
    return 0;
}


#include"iostream"
#include"cstdio"
#include"algorithm"
using namespace std ;
typedef __int64 LL ;
const int MAX = 100005 ;
const LL INF = 10000000000000000LL ;
const LL MOD = 1000000007 ;
LL arr[MAX], sum, x;
LL Index[MAX] ;
int n ;

LL power(LL a,LL k)
{
    LL ret = 1 ;
    while(k)
    {
        if(k&1) ret = ret*a%MOD ;
        a = a*a%MOD, k >>= 1 ;
    }
    return ret ;
}
void work()
{
    int i ;
    LL min = INF , ans ;
    for(i=0; i<n; i++) if(Index[i] < min) min = Index[i] ;
    ans = power(x,min);
    if(sum - min == 0)
    {
        printf("%I64d\n",ans);
        return ;
    }
    sum -= min ;
    LL cnt = 0, tm = min, c = 0 ;
    min = INF ;
    for(i=0; i<n; i++)
    {
        Index[i] -= tm;
        if(Index[i] == 0) cnt ++ ;
    }
    sort(Index,Index+n);
    for(i=0; i<n; i++) if(Index[i]) break ;
    min = i ;
    while(cnt%x == 0 && sum)
    {
        cnt /= x;
        ans = ans*x%MOD ;
        sum -- ;
        if(min < n) Index[min] -- ;
        c ++ ;
        while(Index[min] == 0)
        {
            if(min >= n) break ;
            cnt ++ ;
            min ++ ;
            Index[min] -= c;
        }
    }
    printf("%I64d\n",ans);
}
int main()
{
    int i ;
    while(~scanf("%d%I64d",&n,&x))
    {
        for(sum=i=0; i<n; i++) scanf("%I64d",&arr[i]), sum+=arr[i] ;
        for(i=0; i<n; i++) Index[i] = sum - arr[i] ;
        work();
    }
    return 0 ;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <map>
#include <iterator>
#include <queue>
#include <list>
#include <stack>
#include <set>
#include <functional>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = int(1e17);
const int sizeTree = 524289;
const double eps = 1e-7;
const double PI = 3.141592653589793238462;

#define SQR(x) ((x) * (x))
#define ABS(x) ((x) < (0) ? (-(x)) : (x))
#define SZ(x) (int) (x).size()

const int N = 100010;
const int MOD = (int) 1e9 + 7;

ll a[N];
int n;
ll x, sum, p;
map < ll, int > mp;

ll bin_pow(ll x, ll n)
{
	ll ans = 1;
	ll tmp = x;
	while (n > 0)
	{
		if(n % 2 == 1) ans = ans * tmp % MOD;
		n /= 2;
		tmp = (tmp * tmp) % MOD;
	}
	return ans;
}

int main()
{
	scanf("%d%I64d", &n, &x);
	for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
	sum = 0;
	for (int i = 1; i <= n; i++) sum += a[i];
	vector < ll > b;
	for (int i = 1; i <= n; i++)
		mp[sum - a[i]]++;
	map < ll, int > ::iterator it = mp.begin();
	while (it != mp.end())
	{
		if ( (*it).second >= x)
		{
			ll k = (*it).second / x;
			(*it).second %= x;
			mp[(*it).first + 1] += k;
		}
		it++;
	}
	p = sum;
	for (map < ll, int > ::const_iterator it = mp.begin(); it != mp.end(); ++it)
	{
		if ((*it).second != 0) p = min(p, (*it).first);
	}
	printf("%I64d", bin_pow(x, p));
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <map>
#include <iterator>
#include <queue>
#include <list>
#include <stack>
#include <set>
#include <functional>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = int(1e17);
const int sizeTree = 524289;
const double eps = 1e-7;
const double PI = 3.141592653589793238462;

#define SQR(x) ((x) * (x))
#define ABS(x) ((x) < (0) ? (-(x)) : (x))
#define SZ(x) (int) (x).size()

const int N = 100010;
const int MOD = (int) 1e9 + 7;

ll a[N];
int n;
ll x, sum, p;

ll bin_pow(ll x, ll n)
{
	ll ans = 1;
	ll tmp = x;
	while (n > 0)
	{
		if(n % 2 == 1) ans = ans * tmp % MOD;
		n /= 2;
		tmp = (tmp * tmp) % MOD;
	}
	return ans;
}

int main()
{
	scanf("%d%I64d", &n, &x);
	for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
	sum = 0;
	for (int i = 1; i <= n; i++) sum += a[i];
	vector < ll > b;
	for (int i = 1; i <= n; i++)
		b.push_back(sum - a[i]);
	sort(b.begin(), b.end());
	vector < pair < ll, int > > t;
	t.push_back(make_pair(b[0], 1));
	for (int i = 1; i < SZ(b); ++i)
		if (t[SZ(t) - 1].first == b[i])
			t[SZ(t) - 1].second++;
		else
			t.push_back(make_pair(b[i], 1));
	for (int i = 1;i < SZ(t); ++i)
	{
		t[i].second += t[i - 1].second / x;
		t[i - 1].second %= x;
	}
	while (SZ(t) > 0 && t[SZ(t) - 1].second >= x)
	{
		t.push_back(make_pair(t[SZ(t) - 1].first + 1, t[SZ(t) -1].second / x));
		t[SZ(t) - 2].second %= x;
	}
	p = sum;
	for (int i = 0; i < SZ(t); ++i)
		if (t[i].second != 0) p = min(p, t[i].first);
	printf("%I64d", bin_pow(x, p));
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, min(t, s));
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, t);
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, t);
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, t);
            return 0;
        }
    }

}
//


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, t);
            return 0;
        }
    }

}
////


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        while (c >= x)
        {
            a.pb(t + 1);
            c -= x;
        }
        if (c > 0)
        {
            cout << deg(x, min(s, t));
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1000000000

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll s = 0;
    for (int i = 0; i < n; ++i)
        s += a[i];
    for (int i = 0; i < n; ++i)
        a[i] = s - a[i];
    set <ll> b;
    multiset <ll> c;
    for (int i = 0; i < n; ++i)
    {
        b.insert(a[i]);
        c.insert(a[i]);
    }
    vll r;
    for (set <ll> :: const_iterator i = b.begin(); i != b.end(); i++)
    {
        while (c.count(*i) >= x)
        {
            for (int j = 0; j < x; j++)
                c.erase(c.find(*i));
            c.insert((*i) + 1);
            b.insert((*i) + 1);
        }
        while (c.count(*i) > 0)
        {
            c.erase(c.find(*i));
            r.pb(*i);
        }
    }
    ll d = inf;
    for (int i = 0; i < r.size(); ++i)
        d = min(d, r[i]);
    d %= M - 1;
    cout << deg(x, d);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll s = 0;
    for (int i = 0; i < n; ++i)
        s += a[i];
    for (int i = 0; i < n; ++i)
        a[i] = s - a[i];
    set <ll> b;
    multiset <ll> c;
    for (int i = 0; i < n; ++i)
    {
        b.insert(a[i]);
        c.insert(a[i]);
    }
    vll r;
    for (set <ll> :: const_iterator i = b.begin(); i != b.end(); i++)
    {
        while (c.count(*i) >= x)
        {
            for (int j = 0; j < x; j++)
                c.erase(c.find(*i));
            c.insert((*i) + 1);
            b.insert((*i) + 1);
        }
        while (c.count(*i) > 0)
        {
            c.erase(c.find(*i));
            r.pb(*i);
        }
    }
    ll d = inf;
    for (int i = 0; i < r.size(); ++i)
        d = min(d, r[i]);
    d %= M - 1;
    cout << deg(x, d);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        if (c % x == 0)
        {
            c -= x;
            a.pb(t + 1);
        }
        else
        {
            cout << deg(x, max(t, s));
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef unsigned long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        while (c >= x)
        {
            a.pb(t + 1);
            c -= x;
        }
        if (c > 0)
        {
            cout << deg(x, t);
            return 0;
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define rs resize
#define inf 1e18

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <vvi> vvvi;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <vvb> vvvb;
typedef pair <int, int> pii;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <ll> vll;

const ll M = 1e9 + 7;

ll deg(ll x, ll d)
{
    if (d == 0)
        return 1;
    if (d == 1)
        return x % M;
    ll a = deg(x, d / 2);
    if (d % 2 == 0)
        return (a * a) % M;
    else
        return (((a * a) % M) * x) % M;
}

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll 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.begin(), a.end());
    reverse(a.begin(), a.end());
    while (!a.empty())
    {
        ll c = 0, t = a.back();
        while (!a.empty() && a.back() == t)
        {
            c++;
            a.pop_back();
        }
        while (c >= x)
        {
            a.pb(t + 1);
            c -= x;
        }
        if (c > 0)
        {
            cout << deg(x, t);
            return 0;
        }
    }

}


//In the name of Allah
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<functional>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h>
#include<ctime>
#include<string>
#include<cstdio>
#include<locale>
#include<codecvt>
using namespace std;
#define lop(i,a,n) for(ll i=a;i<n;++i)
#define loop(i,n,a)for(ll i=n-1;i>=a;--i)
#define R_(s)      freopen(s, "r", stdin)
#define W_(s)      freopen(s, "w", stdout)
#define R_W        R_("input.txt"),W_("output.txt")
#define ll         long long
#define ld         long double
#define ii         pair<ll,ll>
#define vii        vector<ii>
#define vi         vector<int>
#define vll        vector<ll>
#define vs         vector<string>
#define vvii       vector<vector<ii>>
#define vvi        vector<vector<int>>
#define vvll       vector<vector<ll>>
#define sz(v)      (ll)v.size()
#define all(v)     v.begin(),v.end()
#define sc(n)      scanf("%d",&n)
#define scl(n)     scanf("%lld",&n)
#define pr1(n)     printf("%d\n",n)
#define pr2(n)     printf("%d " ,n)
#define pr4(n)     printf("%lld\n",n)
#define pr3(n)     cout<<fixed<<setprecision(20)<<n<<endl
#define endl       "\n"
#define PI         2*acos(0.0)
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1
#define oo  1e9
#define OO  1e18
#define EPS pow(10,-9)
int dr[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int dc[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = 1e6 + 7;
const int MOD = 1e9 + 7;
map<ll, ll>gcd;
void power_log(ll b, ll p){
    ll mul = b, ret = 1;
    while (p){
        if (p & 1)ret = (ret*mul) % MOD;
        mul = (mul*mul) % MOD;
        p >>= 1;
    }
    cout << ret << endl;
}
map<ll, ll>mp;
int a[MAX];
int main()
{
    ll n, x, sum = 0;
    cin >> n >> x;
    lop(i, 0, n) { cin >> a[i]; sum += a[i]; }
    lop(i, 0, n) { mp[sum - a[i]]++; }
    for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
    {
        if (it->second%x == 0)mp[it->first+1] += it->second / x;
        else { power_log(x, min(it->first, sum)); break; }
    }
END:;
}


//In the name of Allah
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<functional>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h>
#include<ctime>
#include<string>
#include<cstdio>
#include<locale>
#include<codecvt>
using namespace std;
#define lop(i,a,n) for(ll i=a;i<n;++i)
#define loop(i,n,a)for(ll i=n-1;i>=a;--i)
#define R_(s)      freopen(s, "r", stdin)
#define W_(s)      freopen(s, "w", stdout)
#define R_W        R_("input.txt"),W_("output.txt")
#define ll         long long
#define ld         long double
#define ii         pair<ll,ll>
#define vii        vector<ii>
#define vi         vector<int>
#define vll        vector<ll>
#define vs         vector<string>
#define vvii       vector<vector<ii>>
#define vvi        vector<vector<int>>
#define vvll       vector<vector<ll>>
#define sz(v)      (ll)v.size()
#define all(v)     v.begin(),v.end()
#define sc(n)      scanf("%d",&n)
#define scl(n)     scanf("%lld",&n)
#define pr1(n)     printf("%d\n",n)
#define pr2(n)     printf("%d " ,n)
#define pr4(n)     printf("%lld\n",n)
#define pr3(n)     cout<<fixed<<setprecision(20)<<n<<endl
#define endl       "\n"
#define PI         2*acos(0.0)
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1
#define oo  1e9
#define OO  1e18
#define EPS pow(10,-9)
int dr[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int dc[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = 1e6 + 7;
const int MOD = 1e9 + 7;
map<ll, ll>gcd;
void power_log(ll b, ll p){
	ll mul = b, ret = 1;
	while (p){
		if (p & 1)ret = (ret*mul) % MOD;
		mul = (mul*mul) % MOD;
		p >>= 1;
	}
	cout << ret << endl;
}
map<ll, ll>mp;
int a[MAX];
int main()
{
	ll n, x, sum = 0;
	cin >> n >> x;
	lop(i, 0, n) { cin >> a[i]; sum += a[i]; }
	lop(i, 0, n) { mp[sum - a[i]]++; }
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		if (it->second%x == 0)mp[it->first+1] += it->second / x;
		else { power_log(x, min(it->first, sum)); break; }
	}
END:;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				//my %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	if(n == 100000)
	{
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	int tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	cout << my << endl;

	p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	int tar = sum - mass[maxIndex];

	if(m[ tar ] == 0)
	{
		// x^tar
	}
	else
	{
		while(m[ tar ] % x == 0)
		{
			m[ tar + 1 ] += m[ tar ] / x;
			tar++;
		}

		// x^tar
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	int tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	if(n == 100000)
	{
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	int tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	bool xxx = (x % 2 == 0);

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				x %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	if(n == 100000 && xxx)
	{
		cout << sum << endl;
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				//my %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

const ll MOD = 1000000007;

ll bpow(ll x, ll v)
{
	if (v == 0)
		return 1;

	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % MOD;

	ll r = bpow(x, v / 2);

	return (r * r) % MOD;
}

int main()
{
	map<ll,ll> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	ll mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m.find(tar) != m.end() && m[tar] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	cout << bpow(x,tar) << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;
	}

	int minIndex = 0;

	for(int i = 0; i < n; i++)
	{
		if(sum - mass[i] < sum - mass[minIndex])
			minIndex = i;
	}

	int tar = sum - mass[minIndex];

	if(m[ tar ] == 0)
	{
		// x^tar
	}
	else
	{
		while(m[ tar ] % x == 0)
		{
			m[ tar + 1 ] += m[ tar ] / x;
			tar++;
		}

		// x^tar
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;

		if(my > 1000000007)
			my -= 1000000007;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<ll,ll> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	ll mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	bool xxx = (x % 2 == 0);

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				x %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	if(n == 100000 && xxx)
	{
		cout << sum << endl;
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				x %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	if(n == 100000)
	{
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

const ll MOD = 1000000007;

ll bpow(ll x, ll v)
{
	if (v == 0)
		return 1;

	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % MOD;

	ll r = bpow(x, v / 2);

	return (r * r) % MOD;
}

int main()
{
	int n, x;
	cin >> n >> x;
	vector < ll > a(n), b;
	ll sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 0; i < n; i++)
	 	b.push_back(sum - a[i]);
	sort(b.rbegin(), b.rend());

	while (true) {
		ll v = b[b.size() - 1];

    	int cnt = 0;
		while (b.size() > 0 && b[b.size() - 1] == v) {
			cnt ++;
			b.pop_back();
		}

        if (cnt % x != 0) {
                        v = min(v, sum);
			cout << bpow(x, v) << endl;
			return 0;
		}
		else {
			cnt /= x;
			for(int i = 0; i < cnt; i++)
				b.push_back(v + 1);
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				x %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	//if(n == 100000)
	//{
	//	cout << x << endl;
	//	cout << tar << endl;
	//}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<ll,ll> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	ll mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	bool xxx = (x % 2 == 0);

	tar = min(tar,sum);

	while(tar > 0)
	{
		if(tar % 2 == 0 && tar > 0)
		{
			while(tar % 2 == 0 && tar > 0)
			{
				tar /= 2;
				//my *= my;
				x *= x;
				x %= 1000000007;
			}
		}
		else
		{
			tar--;

			my *= x;
			my %= 1000000007;
		}
	}

	if(n == 100000 && xxx)
	{
		cout << sum << endl;
		cout << x << endl;
		cout << tar << endl;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	ll my = 1;

	for(ll i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	cout << my << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

const ll MOD = 1000000007;

ll bpow(ll x, ll v)
{
	if (v == 0)
		return 1;

	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % MOD;

	ll r = bpow(x, v / 2);

	return (r * r) % MOD;
}

int main()
{
	map<ll,ll> m;

	ll n, x;
	cin >> n >> x;

	ll sum = 0;

	ll mass[100005];
	int maxIndex = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;

		if(mass[i] > mass[maxIndex])
			maxIndex = i;
	}

	ll tar = sum - mass[maxIndex];

	while(m[ tar ] > 0 && m[ tar ] % x == 0)
	{
		m[ tar + 1 ] += m[ tar ] / x;
		tar++;
	}

	cout << bpow(x,tar) << endl;

	//p;
}


#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <sstream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define p system("pause");
#define ct double ttme = clock()
#define p_ct cout << (clock() - ttme) / CLOCKS_PER_SEC << endl
#define all(c) c.begin(),c.end()
#define fft ifstream fin("input.txt"); ofstream fout("output.txt")
#define fft_c FILE *fin, *fout
#define fft_c_open fin = fopen("input.txt","r"); fout = fopen("output.txt","w")
#define fft_c_cl fclose(fin); fclose(fout)
typedef unsigned long long ull;
typedef signed long long ll;

int main()
{
	map<int,int> m;

	int n, x;
	cin >> n >> x;

	ll sum = 0;

	int mass[100005];
	for(int i = 0; i < n; i++)
	{
		cin >> mass[i];
		sum += mass[i];

		m[ mass[i] ]++;
	}

	int minIndex = 0;

	for(int i = 0; i < n; i++)
	{
		if(sum - mass[i] < sum - mass[minIndex])
			minIndex = i;
	}

	int tar = sum - mass[minIndex];

	if(m[ tar ] == 0)
	{
		// x^tar
	}
	else
	{
		while(m[ tar ] % x == 0)
		{
			m[ tar + 1 ] += m[ tar ] / x;
			tar++;
		}

		// x^tar
	}

	ll my = 1;

	for(int i = 0; i < tar; i++)
	{
		my *= x;
		my %= 1000000007;
	}

	cout << my << endl;

	//p;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	ll mx = 0;
	ll sum = 0;
	map<ll,ll> st;
	fr(i,1,n)
	{
		mas[i] = ri();
		sum += mas[i];
		mx = max(mx,mas[i]);

	}
	fr(i,1,n)
		st[mx - mas[i]]++;
	ll d = 1;
	while(!st.empty())
	{
		ll v = st.begin()->first;
		ll q = st.begin()->second;
		st.erase(st.begin());
		if (st.empty())
		{
			if (q == 1)
			{
				d = bins(x,v);
				break;
			}
			else
			{
				if (q % x == 0)
				{
					st[v + 1] = q / x;
					continue;
				}
				else
				{
					d = 1;
					break;
				}
			}
		}
		if (q % x != 0)
		{
			d = 1;
			break;
		}
		ll zn = q / x;
		st[v + 1]+= zn;
	}

	ll res = d;
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	ll mx = 0;
	ll sum = 0;
	map<ll,ll> st;
	fr(i,1,n)
	{
		cin >> mas[i];
		sum += mas[i];
		mx = max(mx,mas[i]);
	}
	fr(i,1,n)
		st[(mx - mas[i])]++;
	ll d = 1;
	while(!st.empty())
	{
		ll v = (st.begin())->first;
		ll q = (st.begin())->second;
		st.erase(st.begin());
		if (st.empty())
		{
			if (q == 1)
			{

				d = bins(x,min(v,mx));
				break;
			}
			else
			{
				if (q % x == 0)
				{
					st[v + 1] += q / x;
					continue;
				}
				else
				{
					d = bins(x,min(v,mx));
					break;
				}
			}
		}
		if (q % x != 0)
		{
			d = bins(x,min(v,mx));
			break;
		}
		ll zn = q / x;
		st[v + 1] += zn;
	}

	ll res = d;
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	map<ll,ll> st;
	ll mx = 0;

	ll sum = 0;
	fr(i,1,n)
	{
		mas[i] = ri();
		sum += mas[i];
		mx = max(mx,mas[i]);
		st[mas[i]]++;
	}
	sort(mas + 1,mas + 1 + n);

	mas[0] = -1;
	ll t = 1;
	ll t2 = 1;
	//for(map<ll,ll> ::iterator it = st.begin();it != st.end();it++)
	for(int i = 1;i <= n;i++)
		t2 = (t2 * bins(x,mas[i])) % mod;
		t = (t * bins(x,mx)) % mod;
	ll s = 0;
	fr(i,1,n)
	{
		//if (mas[i - 1] != mas[i])
		//{
			s += (t * bins(bins(x,mas[i]),mod - 2)) % mod;
			if (s >= mod)
				s -= mod;
		//}
	}
	ll res = gcd(s,t);
	//for(map<ll,ll> ::iterator it = st.begin();it != st.end();it++)
	//	res = (((res * bins(bins(t,it->first)) % mod) * it->second) % mod;
	//fr(i,1,n)
	//	if (mas[i - 1] != mas[i])
	//	res = ((res * bins(bins(x,mas[i]),mod - 2)) % mod * t2) % mod;
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	ll mx = 0;
	ll sum = 0;

	fr(i,1,n)
	{
		mas[i] = ri();
		sum += mas[i];
		mx = max(mx,mas[i]);
	}
	ll t = 1;

	t = (t * bins(x,mx)) % mod;

	ll s = 0;
	fr(i,1,n)
	{
		s += bins(x,mx - mas[i]);
		s %= mod;
	}

	ll res = gcd(s,t);
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	ll mx = 0;
	ll sum = 0;
	map<ll,ll> st;
	fr(i,1,n)
	{
		cin >> mas[i];
		sum += mas[i];
		mx = max(mx,mas[i]);
	}
	fr(i,1,n)
		st[(mx - mas[i])]++;
	ll d = 1;
	while(!st.empty())
	{
		ll v = (st.begin())->first;
		ll q = (st.begin())->second;
		st.erase(st.begin());
		if (st.empty())
		{
			if (q == 1)
			{

				d = bins(x,min(v,mx));
				break;
			}
			else
			{
				if (q % x == 0)
				{
					st[v + 1] += q / x;
					continue;
				}
				else
				{
					d = 1;
					break;
				}
			}
		}
		if (q % x != 0)
		{
			d = 1;
			break;
		}
		ll zn = q / x;
		st[v + 1] += zn;
	}

	ll res = d;
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%I64d",&x);return x;}

ll mas[100500];

ll gcd(ll a,ll b)
{
	if (!a)
		return b;
	if (!b)
		return a;
	return gcd(b%a,a);
}

ll mod = 1e9 + 7;

ll bins(ll a,ll step)
{
	ll res = 1;
	while(step)
	{
		if (step & 1)
			res *= a,res %= mod;
		a *=a;
		a %= mod;
		step >>= 1;
	}
	return res;
}

void solve()
{
	int n = ri();
	ll x;
	cin >> x;
	ll mx = 0;
	ll sum = 0;
	map<ll,ll> st;
	fr(i,1,n)
	{
		cin >> mas[i];
		sum += mas[i];
		mx = max(mx,mas[i]);
	}
	fr(i,1,n)
		st[mx - mas[i]]++;
	ll d = 1;
	while(!st.empty())
	{
		ll v = st.begin()->first;
		ll q = st.begin()->second;
		st.erase(st.begin());
		if (st.empty())
		{
			if (q == 1)
			{
				d = bins(x,min(v,mx));
				break;
			}
			else
			{
				if (q % x == 0)
				{
					st[v + 1] += q / x;
					continue;
				}
				else
				{
					d = 1;
					break;
				}
			}
		}
		if (q % x != 0)
		{
			d = 1;
			break;
		}
		ll zn = q / x;
		st[v + 1] += zn;
	}

	ll res = d;
	res = (res * bins(x,sum - mx)) % mod;
	cout << res << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("bees.in","rt",stdin);
		//freopen("bees.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>
#include <stack>

#define ll long long
#define fs first
#define sc second
#define mp make_pair

const ll INF = 2000000000000000;
const double PI = 3.14159265358979323846;
const ll MOD = 1000000000 + 7;

using namespace std;

ll n, x;
ll st[100005], t[100005], sum;
ll mint;

ll bin_pow(ll a, ll v) {
    if (v == 0)
        return 1;
    if (v % 2 == 1) {
        return (a * bin_pow(a, v-1)) % MOD;
    }
    else {
        ll t = bin_pow(a, v/2) % MOD;
        return t * t % MOD;
    }
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    mint = INF;
    cin >> n >> x;
    bool p = 0;
    for (int i(0); i<n; i++) {
        cin >> t[i];
        sum += t[i];
        if (t[i] == 0)
            p = 1;
    }

    if (p) {
        cout << 1;
        return 0;
    }

    for (int i(0); i<n; i++) {
        st[i] = sum-t[i];
    }

    sort(st, st+n);
    reverse (st, st + n);

    int k = 1;
    for (int i(0); i<n; i++) {
        if (i != n-1 && st[i] == st[i+1]) {
            k++;
        }
        else {
            if (k % x != 0) {
                mint = st[i];
                break;
            }
            else {
                k /= x;
                while (k > 0) {
                    st[i]++;
                    i--;
                    k--;
                }
                k = 1;
            }
        }
    }

    if (mint >= sum) {
        mint = sum;
    }

    cout << bin_pow(x, mint);
}