#include #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)< P; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector

vp; typedef vector vs; const int MAX_N = 200000; #define getchar getchar_unlocked inline int in() { int n = 0; short c; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } int inv[MAX_N],fac[MAX_N],finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i=2;i>= 1; } return ret; } const double PI = acos(-1); complex operator* (const complex a, const complex b){ return complex(a.real()*b.real()-a.imag()*b.imag(),a.real()*b.imag()+a.imag()*b.real()); } vector > fft(vector > a,bool rev = false) { int n = a.size(),h = 0; for(int i = 0; 1 << i < n; i++) h++; //バタフライ演算前の係数の並び替え rep(i,n){ int j = 0; rep(k,h){ j |= (i >> k & 1) << (h-1-k); } if (i < j) swap(a[i], a[j]); } //バタフライ演算 for(int i = 1; i < n; i *= 2) { rep(j,i){ complex w = polar((double)1.0, 2*PI/(i*2)*(rev?-1:1)*j); for(int k = 0; k < n; k += i * 2) { complex s = a[j+k]; complex t = a[j+k+i]*w; a[j+k] = s+t; a[j+k+i] = s-t; } } } if (rev) rep(i,n) a[i] /= n; return a; } void mul(vector& a, vector& b, vector& c) { int s = (int)a.size() + (int)b.size() - 1,t = 1; while (t < s) t *= 2; vector > A(t), B(t); c.resize(t); rep(i,a.size()) A[i].real(a[i]); rep(i,b.size()) B[i].real(b[i]); A = fft(A),B = fft(B); rep(i,t) A[i] *= B[i]; A = fft(A, true); c.resize(s); //整数に直す rep(i,s) c[i] = round(A[i].real()); } vector c[2*MAX_N]; int cnt[MAX_N]; int main() { int n = in(), B = in(); rep(i,n){ cnt[in()]++; } make(); int id = 0, num = 0; priority_queue, greater

> que; rrep(i,MAX_N){ if(!cnt[i]) continue; c[num] = {prod(id+cnt[i]-1, cnt[i]) % MOD, (int)((ll)prod(id+cnt[i]-1, cnt[i]-1) * cnt[i] % MOD)}; que.push(P(2, num++)); id += cnt[i]; } while(len(que) >= 2){ int p = que.top().se; que.pop(); int q = que.top().se; que.pop(); mul(c[p], c[q], c[num]); que.push(P(len(c[num]), num)); num++; } int index = que.top().se; int ans = 0, nB = 1; rep(i, len(c[index])){ ans = (ans + (((ll)c[index][i] * i) % MOD) * nB) % MOD; nB = (ll)nB * B % MOD; } cout << ans << "\n"; return 0; }