#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[30000];
int main(){
	ll n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&a[i]);
	ll ans=0;
	rep(i,n){
		ll c1=0,c2=0;
		for(int j=0;j<i;j++){
			if(a[j]>a[i])c1++;
		}
		rep(j,n){
			if(a[j]>a[i])c2++;
		}
		ll d=(K-1)*K/2%MOD*c2+c1*K;
		(ans+=d)%=MOD;
	}
	cout<<ans<<endl;
}