#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

set<INT> s;

map<INT, int> cnt;

long long a[100010],b[100010];

int main (){

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

		int n,x;

		scanf("%d %d",&n,&x);

		for(int i=1;i<=n;i++) scanf("%d ",&a[i]);

		int N=0;

		for(int i=1;i<=n;i++) N+=a[i];

		for(int i=1;i<=n;i++) b[i]=N-a[i];

		for(int i=1;i<=n;i++){

			cnt[b[i]]++;

			s.insert(b[i]);

			while(cnt[b[i]]==x){

				s.erase(b[i]);

				cnt[b[i]]=0;

				s.insert(b[i]+1);

				cnt[b[i]+1]++;

				b[i]++;

			}

		}

		INT u=*s.begin();

		smin(u, N);

		println(power(x, u, mod));

	return 0;

}


#include<bits/stdc++.h>

#define mod 1000000007

#define NN 100100

using namespace std;

typedef long long INT;

map<INT,INT> cnt;

INT pow(int p,INT k){

	if(k==0) return 1;

	INT kk=pow(p,k/2);

	if(k%2==1) return kk*kk%mod*p%mod;

	return kk*kk%mod;

}

INT a[NN],aa[NN];

int main(){

//	freopen("in.txt","r",stdin);

	int n,x;

	INT ans,sum=0,lenn,len;

	cin>>n>>x;

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

	for(int i=0;i<n;i++)	{ aa[i]=sum-a[i]; cnt[aa[i]]++; }

	sort(aa,aa+n);

	lenn=n;

	len=unique(aa,aa+n)-aa;

	while(lenn!=len){

		lenn=len;

		for(int i=0;i<len;i++){

			int p=0;

			INT m;

			while(!(cnt[aa[i]]%x)) cnt[aa[i]]/=x,p++,m=cnt[aa[i]];

			aa[i]+=1LL*p;

			cnt[aa[i]]=m;

		}

		sort(aa,aa+len);

		for(int i=len-1;i>0;i--) if(aa[i]==aa[i-1])

			cnt[aa[i-1]]+=cnt[aa[i]],cnt[aa[i]]=0;

		len=unique(aa,aa+len)-aa;

	}

	ans=pow(x,aa[0]);

	cout<<ans<<endl;

	return 0;

}


#include<bits/stdc++.h>

#define mod 1000000007

#define NN 100100

using namespace std;

typedef long long INT;

INT pow(int x,INT y){

	if(y==0) return 1;

	INT k=pow(x,y/2);

	if(y%2) return k*k%mod*x%mod;

	return k*k%mod;

}

map<int,int> cnt;

int a[NN];

int main(){

//	freopen("in.txt","r",stdin);

	int n,k,x;

	INT sum=0;

	cin>>n>>x;

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

	sort(a,a+n);

	sum-=a[n-1];

	for(int i=0;i<n;i++) cnt[a[n-1]-a[i]]++;

	for(int i=0;i<25;i++){

		if(cnt[i] && cnt[i]%x) { k=i; break; }

		cnt[i+1]+=cnt[i]/x;

	}

	sum+=1LL*k;

	cout<<pow(x,sum)<<endl;

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT m, INT ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

int n;

INT a[NN], b[NN];

INT x, N;

multiset<INT> s;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	gn(n, x);

	for(int i=0; i<n; i++) {

		gn(a[i]);

		N+=a[i];

	}

	for(int i=0; i<n; i++) b[i]=N-a[i];

	sort(b, b+n);

	for(int i=0; i<n; i++) {

		INT u=b[i];

		s.insert(u);

		while(s.count(u)==x) {

			s.erase(u);

			s.insert(++u);

		}

	}

	INT u=*s.begin();

	smin(u, N);

	println(power(x, u, mod));

}


ScliOJ

17313 17313/

359_C

#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

int n;

INT a[NN], b[NN];

INT x, N;

set<INT> s;

map<INT, int> cnt;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n,x;

	scanf("%d%d",&n,&x);

	for(int i=0; i<n; i++) {

		scanf("%d",&a[i]);

		N+=a[i];

	}

	for(int i=0; i<n; i++) b[i]=N-a[i];

	sort(b, b+n);

	for(int i=0; i<n; i++) {

		INT u=b[i];

		s.insert(u);

		cnt[u]++;

		while(cnt[u]==x) {

			s.erase(u);

			cnt[u]=0;

			s.insert(++u);

			cnt[u]++;

		}

	}

	INT u=*s.begin();

	smin(u, N);

	println(power(x, u, mod));

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT m, INT ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

int n;

INT a[NN], b[NN];

INT x, N;

multiset<INT> s;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	gn(n, x);

	for(int i=0; i<n; i++) {

		gn(a[i]);

		N+=a[i];

	}

	for(int i=0; i<n; i++) b[i]=N-a[i];

	sort(b, b+n);

	for(int i=0; i<n; i++) {

		INT u=b[i];

		s.insert(u);

		while(s.count(u)==x) {

			s.erase(u);

			s.insert(++u);

		}

	}

	println(power(x, *s.begin(), mod));

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT m, INT ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

INT a[NN], b[NN];

int n;

INT x, ans;

multiset<INT> s;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	gn(n, x);

	for(int i=1; i<=n; i++) gn(a[i]);

	INT N=0;

	for(int i=1; i<=n; i++) N+=a[i];

	for(int i=1; i<=n; i++) b[i]=N-a[i];

	sort(b+1, b+n+1);

	ans=power(x, b[1], mod);

	for(int i=0; i<n; i++) a[i]=b[i+1]-b[1];

	for(int i=0; i<n; i++) {

		s.insert(a[i]);

		INT u=a[i];

		while(s.count(u)==x) {

			s.erase(u);

			s.insert(++u);

		}

	}

	ans=1LL*ans*power(x, *s.begin(), mod)%mod;

	println(ans);

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT m, INT ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

INT a[NN], b[NN];

int n;

INT x, ans;

multiset<INT> s;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	gn(n, x);

	for(int i=1; i<=n; i++) gn(a[i]);

	INT N=0;

	for(int i=1; i<=n; i++) N+=a[i];

	for(int i=1; i<=n; i++) b[i]=N-a[i];

	sort(b+1, b+n+1);

	ans=power(x, b[1], mod);

	for(int i=0; i<n; i++) a[i]=b[i+1]-b[1];

	for(int i=0; i<n; i++) {

		s.insert(a[i]);

		INT u=a[i];

		while(s.count(u)==x) {

			s.erase(u);

			s.insert(++u);

		}

	}

	if(N-b[1]>0) ans=1LL*ans*power(x, *s.begin(), mod)%mod;

	println(ans);

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

set<long long> s;

map<long long,int> cnt;

int a[100010],b[100010];

int main (){

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

		int n,x;

		scanf("%d %d",&n,&x);

		for(int i=1;i<=n;i++) scanf("%d ",&a[i]);

		int N=0;

		for(int i=1;i<=n;i++) N+=a[i];

		for(int i=1;i<=n;i++) b[i]=N-a[i];

		for(int i=1;i<=n;i++){

			cnt[b[i]]++;

			s.insert(b[i]);

			if(cnt[b[i]]==x){

				s.erase(b[i]);

				cnt[b[i]]=0;

				s.insert(b[i]+1);

				cnt[b[i]+1]++;

			}

		}

		INT u=*s.begin();

		smin(u, N);

		println(power(x, u, mod));

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

int n;

INT a[NN], b[NN];

INT x, N;

multiset<INT> s;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	gn(n, x);

	for(int i=0; i<n; i++) {

		gn(a[i]);

		N+=a[i];

	}

	for(int i=0; i<n; i++) b[i]=N-a[i];

	sort(b, b+n);

	for(int i=0; i<n; i++) {

		INT u=b[i];

		s.insert(u);

		while(s.count(u)==x) {

			s.erase(u);

			s.insert(++u);

		}

	}

	INT u=*s.begin();

	smin(u, N);

	println(power(x, u, mod));

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define hmod 911382323

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define LEN(a) (a.length())

#define ls (u<<1)

#define rs (ls + 1)

#define mid (st + ed >> 1)

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define rands(n) (rand()%n+1)

#define rand0(n) (rands(n)-1)

#define Rands(n) ((INT)rand()*rand()%n+1)

#define Rand0(n) (Rands(n)-1)

#define PQ priority_queue<INT, vector<INT>, greater<INT> >

#define rep(i, a, b) for(int i=a; i<b; i++)

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define shit(a) (1 << (a))

#define all(a) ((a).begin(), (a).end())

#define rev(a) (power(a, mod-2, mod))

using namespace std;

typedef long long INT;

typedef unsigned long long UINT;

typedef unsigned int uint;

typedef complex<double> Complex;

typedef double DO;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef pair<int, pii> pip;

typedef pair<DO, DO> pdd;

typedef pair<int, DO> pid;

typedef pair<DO, int> pdi;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

PQ pq;

#define NN 100111

INT a[NN], sum;

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, x;

	gn(n, x);

	for(int i=1; i<=n; i++) gn(a[i]), sum+=a[i];

	for(int i=1; i<=n; i++) pq.push(sum-a[i]);

	while(!pq.empty()) {

		INT u=pq.top();

		//cerr << u << endl;

		int cnt=0;

		while(!pq.empty()) {

			if(pq.top() == u) pq.pop();

			else break;

			cnt++;

		}

		if(cnt % x) return cout << power(x, u, mod) << endl, 0;

		for(int i=0; i<cnt/x; i++) pq.push(u+1);

	}

	return 0;

}


#include<bits/stdc++.h>

#define mod 1000000007

#define NN 100100

using namespace std;

typedef long long INT;

INT pow(int x,INT y){

	if(y==0) return 1;

	INT k=pow(x,y/2);

	if(y%2) return k*k%mod*x%mod;

	return k*k%mod;

}

map<int,int> cnt;

int a[NN];

int main(){

//	freopen("in.txt","r",stdin);

	int n,k,x;

	INT sum=0;

	cin>>n>>x;

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

	sort(a,a+n);

	sum-=a[n-1];

	for(int i=0;i<n;i++) cnt[a[n-1]-a[i]]++;

	for(int i=0;i<25;i++){

		if(cnt[i] && cnt[i]%x) { k=i; break; }

		cnt[i+1]+=cnt[i]/x;

	}

	sum+=1LL*min(k,a[n-1]);

	cout<<pow(x,sum)<<endl;

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, INT b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100010

int n;

INT a[NN], b[NN];

INT x, N;

set<INT> s;

map<INT, int> cnt;

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n,x;

	scanf("%d%d",&n,&x);

	for(int i=0; i<n; i++) {

		scanf("%d",&a[i]);

		N+=a[i];

	}

	for(int i=0; i<n; i++) b[i]=N-a[i];

	sort(b, b+n);

	for(int i=0; i<n; i++) {

		INT u=b[i];

		s.insert(u);

		cnt[u]++;

		while(cnt[u]==x) {

			s.erase(u);

			cnt[u]=0;

			s.insert(++u);

			cnt[u]++;

		}

	}

	INT u=*s.begin();

	smin(u, N);

	println(power(x, u, mod));

}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    int nn=98304,cc=0;
    while(nn%2==0&&nn)
    {
        cc++;
        nn/=2;
    }
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
    {
        u[i]=1;
        if(num[i]>maxx)
        {
            id=i;
            maxx=num[i];
        }
        //maxx=max(maxx,num[i]);
    }
    for(int i=0;i<n;i++)
        if(i!=id)t=(t+num[i])%(mod-1);
    for(int i=0;i<n;i++)
        num[i]=maxx-num[i];
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co&&co%k==0)
        {
            LL c=0,minn=-1;
           while(co&&co%k==0)
           {
               c++;
               co/=k;
           }
           //cout<<"++++"<<endl;
           num[id]=c;
           u[id]=co;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                {
                    if(minn==-1)
                        minn=num[i];
                    else
                        minn=min(num[i],minn);
                }
            }
            if(maxx<minn)
                minn=maxx;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                    num[i]=num[i]-minn;
            }
            t=(t+minn)%(mod-1);
            maxx-=minn;
            if(maxx<=0)
                f=true;
            co=0;
        }
        else
            f=true;
    };
    if(maxx<=0)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                t=(t+u[i])%(mod-1);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int i=0;i<num[i];i++)
                    kk*=k;
                t=(t+kk)%(mod-1);
            }
        }
    }
    //cout<<"++++"<<endl;
    t%=(mod-1);
    //cout<<t<<endl;
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    maxx=num[n-1];
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }

    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        if(maxx<minn)
            minn=maxx;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        maxx-=minn;
        t=(t+minn)%(mod-1);
        if(maxx==0)
            break;
        co=0;
    }
    s=0;
    if(maxx==0)
    {
       // cout<<"+++"<<endl;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                s=(s+u[i])%(mod);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int j=0;j<num[i];j++)
                    kk=(kk*k)%(mod);
                s=(s+kk)%(mod);
            }
        }
    }
    printf("%I64d\n",(Pow(t)%mod)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
    {
        u[i]=1;
        if(num[i]>maxx)
        {
            id=i;
            maxx=num[i];
        }
        //maxx=max(maxx,num[i]);
    }
    for(int i=0;i<n;i++)
        if(i!=id)t=(t+num[i])%(mod-1);
    for(int i=0;i<n;i++)
        num[i]=maxx-num[i];
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co&&co%k==0)
        {
            LL c=0,minn=-1;
           while(co&&co%k==0)
           {
               c++;
               co/=k;
           }
           //cout<<"++++"<<endl;
           num[id]=c;
           u[id]=co;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                {
                    if(minn=-1)
                        minn=num[i];
                    else
                        minn=min(num[i],minn);
                }
            }
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                    num[i]=num[i]-minn;
            }
            t=(t+minn)%(mod-1);
            co=0;
        }
        else
            f=true;
    }
    //cout<<"++++"<<endl;
    t%=(mod-1);
    //cout<<t<<endl;
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    bool f=false;
    LL maxx=0,sum=0,t,s,co=0;
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",num+i);
    for(int i=0;i<n;i++)
    {
        sum+=num[i];
        maxx=max(maxx,num[i]);
    }
    t=sum-maxx;
    //sum-=maxx;
    for(int i=0;i<n;i++)
        num[i]=sum-num[i];
    for(int i=0;i<n;i++)
        num[i]-=(sum-maxx);
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co++;
                num[i]--;
            }
        }
        if(co&&co%k==0)
        {
            t++;
            for(int i=0;i<n;i++)
                num[i]--;
            co=0;
        }
        else
            f=true;
    }
   // cout<<"+++"<<endl;
    t%=(mod-1);
    printf("%lld\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    maxx=num[n-1];
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }

    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        if(maxx<minn)
            minn=maxx;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        maxx-=minn;
        t=(t+minn)%(mod-1);
        if(maxx==0)
            break;
        co=0;
    }
    if(maxx==0)
    {
       // cout<<"+++"<<endl;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                t=(t+u[i])%(mod-1);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int j=0;j<num[i];j++)
                    kk=(kk*k)%(mod-1);
                t=(t+kk)%(mod-1);
            }
        }
    }
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    maxx=num[n-1];
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }

    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        if(maxx<minn)
            minn=maxx;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        maxx-=minn;
        t=(t+minn)%(mod-1);
        if(maxx==0)
            break;
        co=0;
    }
    //cout<<maxx<<endl;
    if(maxx==0)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                t=(t+u[i])%(mod-1);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int j=0;j<num[i];j++)
                    kk*=k;
                t=(t+kk)%(mod-1);
            }
        }
    }
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    int id;
    bool f=false;
    long long maxx=0,sum=0,t=0,s,co=0;
   // t=100000*1000000;
  //  printf("%lld\n",t);
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%lld",num+i);
    for(int i=0;i<n;i++)
    {
        if(num[i]>maxx)
        {
            id=i;
            maxx=num[i];
        }
        //maxx=max(maxx,num[i]);
    }
    for(int i=0;i<n;i++)
        if(i!=id)t=(t+num[i])%(mod-1);
    //sum-=maxx;
    for(int i=0;i<n;i++)
        num[i]=maxx-num[i];
    //for(int i=0;i<n;i++)
      //  num[i]-=(sum-maxx);
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co++;
                num[i]--;
            }
        }
        if(co&&co%k==0)
        {
            t=(t+1)%(mod-1);
            for(int i=0;i<n;i++)
                num[i]--;
            co=0;
        }
        else
            f=true;
    }
   // cout<<"+++"<<endl;
    t%=(mod-1);
    //cout<<t<<endl;
    printf("%lld\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    maxx=num[n-1];
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }

    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        if(maxx<minn)
            minn=maxx;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        maxx-=minn;
        t=(t+minn)%(mod-1);
        if(maxx==0)
            break;
        co=0;
    }
    s=0;
    if(maxx==0)
    {
       // cout<<"+++"<<endl;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                s=(s+u[i])%(mod);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int j=0;j<num[i];j++)
                    kk=(kk*k)%(mod);
                s=(s+kk)%(mod);
            }
        }
    }
    printf("%I64d\n",(Pow(t)%mod+s)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    maxx=num[n-1];
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }

    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        if(maxx<minn)
            minn=maxx;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        maxx-=minn;
        t=(t+minn)%(mod-1);
        if(maxx==0)
            break;
        co=0;
    }
    if(maxx==0)
    {
        cout<<"+++"<<endl;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
                t=(t+u[i])%(mod-1);
            else if(num[i]>0)
            {
                LL kk=u[i];
                for(int j=0;j<num[i];j++)
                    kk*=k;
                t=(t+kk)%(mod-1);
            }
        }
    }
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
    {
        u[i]=1;
        if(num[i]>maxx)
        {
            id=i;
            maxx=num[i];
        }
        //maxx=max(maxx,num[i]);
    }
    for(int i=0;i<n;i++)
        if(i!=id)t=(t+num[i])%(mod-1);
    for(int i=0;i<n;i++)
        num[i]=maxx-num[i];
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co&&co%k==0)
        {
            LL c=0,minn=-1;
           while(co&&co%k==0)
           {
               c++;
               co/=k;
           }
           //cout<<"++++"<<endl;
           num[id]=c;
           u[id]=co;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                {
                    if(minn==-1)
                        minn=num[i];
                    else
                        minn=min(num[i],minn);
                }
            }
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                    num[i]=num[i]-minn;
            }
            t=(t+minn)%(mod-1);
            co=0;
        }
        else
            f=true;
    }
    //cout<<"++++"<<endl;
    t%=(mod-1);
    //cout<<t<<endl;
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
        u[i]=1;
    if(num[n-1]==0)
    {
        puts("1");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
        t=(t+num[i])%(mod-1);
        num[i]=num[n-1]-num[i];
    }
    while(!f)
    {
        LL minn=-1,c=0;
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                //co++;
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co==0||co%k!=0)
            break;
        while(co&&co%k==0)
        {
            c++;
            co/=k;
        }
        //cout<<"+++"<<endl;
        num[id]=c;
        u[id]=co;
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
            {
                if(minn==-1)
                    minn=num[i];
                else
                    minn=min(num[i],minn);
            }
        }
        for(int i=0;i<n;i++)
        {
            if(num[i]>=0)
                num[i]-=minn;
        }
        t=(t+minn)%(mod-1);
        co=0;
    }
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    bool f=false;
    LL maxx=0,sum=0,t,s,co=0;
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%lld",num+i);
    for(int i=0;i<n;i++)
    {
        sum+=num[i];
        maxx=max(maxx,num[i]);
    }
    t=sum-maxx;
    //sum-=maxx;
    for(int i=0;i<n;i++)
        num[i]=sum-num[i];
    for(int i=0;i<n;i++)
        num[i]-=(sum-maxx);
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co++;
                num[i]--;
            }
        }
        if(co&&co%k==0)
        {
            t++;
            for(int i=0;i<n;i++)
                num[i]--;
            co=0;
        }
        else
            f=true;
    }
   // cout<<"+++"<<endl;
    t%=(mod-1);
    printf("%lld\n",Pow(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    bool f=false;
    LL maxx=0,sum=0,t,s,co=0;
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",num+i);
    for(int i=0;i<n;i++)
    {
        sum+=num[i];
        maxx=max(maxx,num[i]);
    }
    t=sum-maxx;
    //sum-=maxx;
    for(int i=0;i<n;i++)
        num[i]=sum-num[i];
    for(int i=0;i<n;i++)
        num[i]-=(sum-maxx);
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co++;
                num[i]--;
            }
        }
        if(co&&co%k==0)
        {
            t++;
            for(int i=0;i<n;i++)
                num[i]--;
            co=0;
        }
        else
            f=true;
    }
   // cout<<"+++"<<endl;
    t%=(mod-1);
    printf("%I64d\n",poW(t)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod=1000000007;
const int maxn=100100;
LL num[maxn],n,k;
LL u[maxn];
LL Pow(LL n)
{
     long long p=1,q=k;
     while(n){
         if(n&1){
             p=p*q%mod;
         }
         n>>=1;
         q=q*q%mod;
     }
     return p;
}
int main()
{
    int nn=98304,cc=0;
    while(nn%2==0&&nn)
    {
        cc++;
        nn/=2;
    }
    //cout<<nn<<endl;
    int id;
    bool f=false;
    LL maxx=0,sum=0,t=0,s,co=0;
    scanf("%I64d%I64d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%I64d",num+i);
    for(int i=0;i<n;i++)
    {
        u[i]=1;
        if(num[i]>maxx)
        {
            id=i;
            maxx=num[i];
        }
        //maxx=max(maxx,num[i]);
    }
    for(int i=0;i<n;i++)
        if(i!=id)t=(t+num[i])%(mod-1);
    for(int i=0;i<n;i++)
        num[i]=maxx-num[i];
    while(!f)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]==0)
            {
                co+=u[i];
                num[i]--;
                id=i;
            }
        }
        if(co&&co%k==0)
        {
            LL c=0,minn=-1;
           while(co&&co%k==0)
           {
               c++;
               co/=k;
           }
           //cout<<"++++"<<endl;
           num[id]=c;
           u[id]=co;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                {
                    if(minn==-1)
                        minn=num[i];
                    else
                        minn=min(num[i],minn);
                }
            }
            if(maxx<minn)
                minn=maxx;
            for(int i=0;i<n;i++)
            {
                if(num[i]>=0)
                    num[i]=num[i]-minn;
            }
            t=(t+minn)%(mod-1);
            maxx-=minn;
            if(maxx<=0)
                f=true;
            co=0;
        }
        else
            f=true;
    };
    if(maxx<=0)
    {
        for(int i=0;i<n;i++)
        {
            if(num[i]>0)
                t=(t+num[i])%(mod-1);
        }
    }
    //cout<<"++++"<<endl;
    t%=(mod-1);
    //cout<<t<<endl;
    printf("%I64d\n",Pow(t)%mod);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 1000000;
const int mod = 1000 * 1000 * 1000 + 7;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	int b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		LL cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	LL D = 0, ans = 1;

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			int dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			LL cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur, st;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map.count(cur) >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map.erase(st + D);
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map.count(cur) >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;
typedef pair <int, int> pii;

const int inf = 1000 * 1000 * 1000;
const int maxn = 1000000;
const int mod = 1000 * 1000 * 1000 + 7;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	int b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <int> Set;
map <int, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		int cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	int D = 0, ans = 1;

	while ((int)Set.size()) {
		int st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st + 0ll, sum)) % mod;
			int dount = Map[st + D];
			Map[st + D] = 0;
			Map[D + min(st + 0ll, sum)] += dount;
			Set.insert(D + min(st + 0ll, sum));
			int cur = D + min(st + 0ll, sum);

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
			D += min(st + 0ll, sum);
			sum -= min(st + 0ll, sum);
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000ll * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur, st;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;
typedef pair <int, int> pii;

const int inf = 1000 * 1000 * 1000;
const int maxn = 1000000;
const int mod = 1000 * 1000 * 1000 + 7;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	int b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <int> Set;
map <int, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
	}

	int D = 0, ans = 1;

	while ((int)Set.size()) {
		int st = *Set.begin();
		Set.erase(st);
		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st + 0ll, sum)) % mod;
			sum -= min(st + 0ll, sum);
			if (Map[st + D] % x == 0) {
				Set.insert(Map[st + D] / x + D + min(st + 0ll, sum));
				Map[Map[st + D] / x + D + min(st + 0ll, sum)]++;
			} else {
				break;
			}
			D += min(st + 0ll, sum);
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, LL a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

set <LL> Set;
map <LL, int> Map;
LL cur, sum;
int n, x, a[maxn];

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		cur = sum - a[i];
                Map[cur]++;
		Set.insert(cur);

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	cout << binpow(x, *Set.begin());

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		LL cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	LL D = 0, ans = 1;

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			int dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			LL cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 200001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, LL a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

set <LL> Set;
map <LL, int> Map;
LL cur, sum;
int n, x, a[maxn];

int main() {
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		cur = sum - a[i];
                Map[cur]++;
		Set.insert(cur);

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	cout << binpow(x, *Set.begin());

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

set <LL> Set;
map <LL, int> Map;
LL cur, sum;
int n, x, a[maxn];

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		cur = sum - a[i];
                Map[cur]++;
		Set.insert(cur);

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	cout << binpow(x, *Set.begin());

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		LL cur = sum - a[i];

		while (Map.count(cur) >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	LL D = 0, ans = 1;

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			int dount = Map[st + D];
			Map.erase(st + D);
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			LL cur = D;

			while (Map.count(cur) >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000 * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int binpow(int x, int a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	int b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		LL cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	LL D = 0, ans = 1;

	while ((int)Set.size()) {
		LL st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			int dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			LL cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <ctime>

using namespace std;

#define F first
#define S second
#define mp(x, y) make_pair(x, y)

typedef long long LL;

const int inf = 1000ll * 1000 * 1000;
const int maxn = 100001;
const int mod = 1000 * 1000 * 1000 + 7;

int b;

int binpow(int &x, LL a) {
	if (a == 0)
		return 1;
	if (a % 2)
		return binpow(x, a - 1) * 1ll * x % mod;
	b = binpow(x, a / 2);
	return b * 1ll * b % mod;
}

int n, x, a[maxn];
LL sum;
set <LL> Set;
map <LL, int> Map;

int main() {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);

	cin >> n >> x;

	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];

	LL D = 0, ans = 1, cur, st;
	int dount;

	for (int i = 0; i < n; i++) {
		Set.insert(sum - a[i]);
		Map[sum - a[i]]++;
		cur = sum - a[i];

		while (Map[cur] >= x) {
			Set.insert(cur + 1);
			Map[cur + 1] += Map[cur] / x;
			Map[cur] %= x;
			if (Map[cur] == 0)
				Set.erase(cur);
			cur++;
		}
	}

	while ((int)Set.size()) {
		st = *Set.begin();
		Set.erase(st);

		if (st > D) {
			st -= D;
			ans = ans * 1ll * binpow(x, min(st, sum)) % mod;
			dount = Map[st + D];
			Map[st + D] = 0;
			D += min(st, sum);
			sum -= min(st, sum);
			Map[D] += dount;
			Set.insert(D);
			cur = D;

			while (Map[cur] >= x) {
				Set.insert(cur + 1);
		        	Map[cur + 1] += Map[cur] / x;
				Map[cur] %= x;
				if (Map[cur] == 0)
					Set.erase(cur);
				cur++;
			}
		} else {
			break;
		}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long Lint;
map <Lint,Lint> mp;
int a,b,ar[100020];

int main()
{
	Lint top=0,k,x,cev=1;
	cin >> a >> b;
	for(int i=1;i<=a;i++)
		cin >> ar[i] , top+=ar[i];

	for(int i=1;i<=a;i++) mp[ top-ar[i] ]++;

	while(1) {
		k= mp.begin()->first ;
		if( mp[k] % b == 0 ) {
			mp[k+1] = mp[k] / b;
			mp.erase(k);
		}
		else break;
	}
	x=b;
	while( k > 0 ) {
		if( k % 2 ) cev = cev * x % MOD;
		x = x * x % MOD;
		k /= 2;
	}

	cout << cev << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long Lint;
map <Lint,Lint> mp;
int a,b,ar[100020];

int main()
{
	Lint top=0,k,cev=1;
	cin >> a >> b;
	for(int i=1;i<=a;i++)
		cin >> ar[i] , top+=ar[i];

	for(int i=1;i<=a;i++) mp[ top-ar[i] ]++;

	while(1) {
		k= mp.begin()->first ;
		if( mp[k] % b == 0 ) {
			mp[k+1] = mp[k] / b;
			mp.erase(k);
		}
		else break;
	}
	for(int i=1;i<=k;i++,cev*=b,cev%=MOD);
	cout << cev << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal,isim;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 , Lint b=0 ) { mal=a; isim=b; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	int i,j,top=0,m,k,maxi=1987654321;

	scanf(" %d %d",&a,&b);

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i<=a ; i++ )
		scanf(" %d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] , i ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		if(k>maxi) break;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else maxi=min( maxi , k );
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%d\n",k);
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 ) { mal=a; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	int i,j,top=0,m,k,maxi=1987654321;

	scanf(" %d %d",&a,&b);

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i<=a ; i++ )
		scanf(" %d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		//~ if(k>maxi) break;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else { maxi=k; break; }
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%d\n",k);
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal,isim;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 , Lint b=0 ) { mal=a; isim=b; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint i,j,k,top=0,m,maxi=1987654321;

	scanf(" %I64d %I64d",&a,&b);

	for( i=1 ; i<=a ; i++ )
		scanf(" %I64d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] , i ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else maxi=min( maxi , k );
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%d\n",k);
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal,isim;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 , Lint b=0 ) { mal=a; isim=b; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint i,j,k,top=0,m,maxi=1987654321;

	scanf(" %i64d %i64d",&a,&b);

	for( i=1 ; i<=a ; i++ )
		scanf(" %i64d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] , i ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else maxi=min( maxi , k );
	}
	k=1;
	//~ printf("%d---------\n",maxi);
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%i64d\n",k);
	//~ printf("asdasdasd\n");
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 ) { mal=a; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint x,i,j,top=0,m,k,maxi=1987654321;

	cin >> a >> b;

	for( i=1 ; i<=a ; i++ )
		cin >> ar[i] , top+=ar[i];

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		//~ if(k>maxi) break;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else { maxi=k; break; }
	}
	k=1;
	x=b;
	while( maxi>0 ) {
		if(maxi%2) k = k * x % MOD;
		x = x * x % MOD;
		maxi /= 2;
	}
	cout << k << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 ) { mal=a; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint x,i,j,top=0,m,k,maxi=1987654321;

	cin >> a >> b;

	for( i=1 ; i<=a ; i++ )
		cin >> ar[i] , top+=ar[i];

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		//~ if(k>maxi) break;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else { maxi=k; break; }
	}
	k=1;
	x=1;
	while( maxi>0 ) {
		if(maxi%2) k = k * x % MOD;
		x = x * x % MOD;
		maxi /= 2;
	}
	cout << k << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 ) { mal=a; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint i,j,top=0,m,k,maxi=1987654321;

	cin >> a >> b;

	for( i=1 ; i<=a ; i++ )
		cin >> ar[i] , top+=ar[i];

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		//~ if(k>maxi) break;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else { maxi=k; break; }
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	cout << k << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal,isim;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 , Lint b=0 ) { mal=a; isim=b; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint i,j,k,top=0,m,maxi=1987654321;

	scanf(" %I64d %I64d",&a,&b);

	if(b==1) {
		printf("1\n");
	}

	for( i=1 ; i<=a ; i++ )
		scanf(" %I64d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] , i ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else maxi=min( maxi , k );
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%d\n",k);
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long int Lint;

struct node {
	Lint mal,isim;
	friend bool operator < (const node &a,const node &b) { return a.mal>b.mal; }
	node( Lint a=0 , Lint b=0 ) { mal=a; isim=b; }
}t;

priority_queue <node> q;
Lint ar[100020],a,b;

int main()
{
	Lint i,j,k,top=0,m,maxi=1987654321;

	scanf(" %I64d %I64d",&a,&b);

	if(b==1) {
		printf("1\n");
		return 0;
	}

	for( i=1 ; i<=a ; i++ )
		scanf(" %I64d",&ar[i]),top+=ar[i];

	for( i=1 ; i <= a ; i++ )
		q.push(node( top-ar[i] , i ));

	while(!q.empty()) {
		t=q.top();
		q.pop();
		k=t.mal;
		m=1;
		while( !q.empty() && t.mal==k && m<b ) {
			t=q.top();
			q.pop();
			m++;
		}
		if(m==b) {
			t.mal=k+1;
			q.push( t );
		}
		else maxi=min( maxi , k );
	}
	k=1;
	for(int i=1;i<=maxi;i++,k*=b,k%=MOD);
	printf("%d\n",k);
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long Lint;
map <Lint,Lint> mp;
int a,b,ar[100020];

int main()
{
	Lint top=0,k,x,cev=1;
	cin >> a >> b;
	for(int i=1;i<=a;i++)
		cin >> ar[i] , top+=ar[i];

	for(int i=1;i<=a;i++) mp[ -ar[i] ]++;

	while(1) {
		k= mp.begin()->first ;
		if( mp[k] % b == 0 ) {
			mp[k+1] = mp[k] / b;
			mp.erase(k);
		}
		else break;
	}
	k = min( k , (Lint)0 );
	k += top;
	x=b;
	while( k > 0 ) {
		if( k % 2 ) cev = cev * x % MOD;
		x = x * x % MOD;
		k /= 2;
	}

	cout << cev << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long Lint;
map <Lint,Lint> mp;
int a,b,ar[100020];

int main()
{
	Lint top=0,k,x,cev=1;
	cin >> a >> b;
	for(int i=1;i<=a;i++)
		cin >> ar[i] , top+=ar[i];

	for(int i=1;i<=a;i++) mp[ -ar[i] ]++;

	while(1) {
		k= mp.begin()->first ;
		if( mp[k] % b == 0 ) {
			mp[k+1] += mp[k] / b;
			mp.erase(k);
		}
		else break;
	}
	k = min( k , (Lint)0 );
	k += top;
	x=b;
	while( k > 0 ) {
		if( k % 2 ) cev = cev * x % MOD;
		x = x * x % MOD;
		k /= 2;
	}

	cout << cev << endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll mnn=a[1];
    for(int i=1;i<=n;i++) mnn=min(mnn,a[i]);
    ll pnt=mnn;
    for(int i=1;i<=n;i++) a[i]-=mnn;
    priority_queue<ll>Que;
    for(int i=1;i<=n;i++)
        Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop(),cnt++;
        while(Que.top()==mn&&!Que.empty()) Que.pop(),cnt++;
        if(cnt%x!=0||Que.empty()) {
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll pnt=a[1];
    for(int i=1;i<=n;i++) pnt=min(pnt,a[i]);
    for(int i=1;i<=n;i++) a[i]-=pnt;
   // for(int i=1;i<=n;i++) printf("a[%d]= %I64d\n",i,a[i]);
    priority_queue<ll,vector<ll>,greater<ll> >Que;
    for(int i=1;i<=n;i++) Que.push(a[i]);
    while(1)
    {
         ll mn=Que.top(),cnt=1,num;Que.pop();
         if(Que.empty()){
             if(mn%x==0&&mn!=0) mn/=x,pnt++;
             printf("%I64d\n",power(x,pnt));
             return 0;
         }
         while(!Que.empty()&&Que.top()==mn) Que.pop(),cnt++;
         if(cnt%x==0){
             pnt++;
             queue<ll>QQ;
             while(!Que.empty()){num=Que.top();QQ.push(num-1);Que.pop();}
             while(!QQ.empty()) {num=QQ.front();Que.push(num);QQ.pop();}
             for(int i=0;i<cnt/x;i++) Que.push(mn);
         }else {
             printf("%I64d\n",power(x,pnt));
             return 0;
         }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll pnt=a[1];
    for(int i=1;i<=n;i++) pnt=min(pnt,a[i]);
    for(int i=1;i<=n;i++) a[i]-=pnt;
   // for(int i=1;i<=n;i++) printf("a[%d]= %I64d\n",i,a[i]);
    priority_queue<ll,vector<ll>,greater<ll> >Que;
    for(int i=1;i<=n;i++) Que.push(a[i]);
    while(1)
    {
         ll mn=Que.top(),cnt=1,num;Que.pop();
         if(Que.empty()){
             if(mn%x==0&&mn!=0) mn/=x,pnt++;
             if(pnt<sum) printf("%I64d\n",power(x,pnt));
             else printf("%I64d\n",power(x,sum));
             return 0;
         }
         while(!Que.empty()&&Que.top()==mn) Que.pop(),cnt++;
         if(cnt%x==0){
             pnt++;
             queue<ll>QQ;
             while(!Que.empty()){num=Que.top();QQ.push(num-1);Que.pop();}
             while(!QQ.empty()) {num=QQ.front();Que.push(num);QQ.pop();}
             for(int i=0;i<cnt/x;i++) Que.push(mn);
         }else {
             if(pnt<sum) printf("%I64d\n",power(x,pnt));
             else printf("%I64d\n",power(x,sum));
             return 0;
         }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll mnn=a[1];
    for(int i=1;i<=n;i++) mnn=min(mnn,a[i]);
    ll pnt=mnn;
    for(int i=1;i<=n;i++) a[i]-=mnn;
    priority_queue<ll>Que;
    for(int i=1;i<=n;i++) Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop();cnt++;
        if(Que.empty()){
            if(mn%x==0) pnt++;
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        while(!Que.empty()&&Que.top()==mn) Que.pop(),cnt++;
        if(cnt%x!=0) {
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll mnn=a[1];
    for(int i=1;i<=n;i++) mnn=min(mnn,a[i]);
    ll pnt=mnn;
    for(int i=1;i<=n;i++) a[i]-=mnn;
    priority_queue<ll>Que;
    for(int i=1;i<=n;i++)
        Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop(),cnt++;
        if(Que.empty())
        {
            if(mn%x==0) pnt++;
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        while(Que.top()==mn&&!Que.empty()) Que.pop(),cnt++;
        if(cnt%x!=0) {
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll mnn=a[1];
    for(int i=1;i<=n;i++) mnn=min(mnn,a[i]);
    ll pnt=mnn;
    for(int i=1;i<=n;i++) a[i]-=mnn;
    priority_queue<ll>Que;
    for(int i=1;i<=n;i++)
        Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop(),cnt++;
        while(Que.top()==mn&&!Que.empty()) Que.pop(),cnt++;
        if(cnt%x!=0) {
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll pnt=a[1];
    for(int i=1;i<=n;i++) pnt=min(pnt,a[i]);
    for(int i=1;i<=n;i++) a[i]-=pnt;
    pnt%=(mod-1);
    priority_queue<ll>Que;
    for(int i=1;i<=n;i++) Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop();cnt++;
        if(Que.empty()){
            while(mn%x==0) pnt++,mn/=x;
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        while(!Que.empty()&&Que.top()==mn) Que.pop(),cnt++;
        if(cnt%x!=0) {
            pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
const int maxn = 100000+5;
ll a[maxn];
ll power(ll a,ll k){
    ll r=1;
    a%=mod;
    while(k){
        if(k&1) r=r*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return r;
}
int main()
{
    ll n,x;
    scanf("%I64d%I64d",&n,&x);
    ll sum=0;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]),sum+=a[i];
    for(int i=1;i<=n;i++) a[i]=sum-a[i];
    ll pnt=a[1];
    for(int i=1;i<=n;i++) pnt=min(pnt,a[i]);
    for(int i=1;i<=n;i++) a[i]-=pnt;
    //pnt%=(mod-1);
    priority_queue<ll,vector<ll>,less<ll> >Que;
    for(int i=1;i<=n;i++) Que.push(a[i]);
    while(1)
    {
        ll mn=Que.top(),cnt=0;
        Que.pop();cnt++;
        if(Que.empty()){
            while(mn%x==0) pnt++,mn/=x;
          //  pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        while(!Que.empty()&&Que.top()==mn) Que.pop(),cnt++;
        if(cnt%x!=0) {
           // pnt%=(mod-1);
            printf("%I64d\n",power(x,pnt));
            return 0;
        }
        else {
            for(int i=0;i<cnt/x;i++)
                Que.push(mn+1);
            pnt++;
        }
    }
    return 0;
}