#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll mod=1e9+7;
ll a[5000];
int main()
{
	ll n,k;
	ll ans=0;
	ll temp=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=n;i<2*n;i++){
		a[i]=a[i-n];
	}
//	cout<<n;
	for(int i=0;i<n;i++){
		for(int j=n;j<2*n;j++){
			if(a[i]>a[j])ans++;
		}
//		cout<<ans<<" ";
		for(int k=i+1;k<n;k++){
//			if(k==n) continue;
			if(a[i]>a[k]) temp++;
		}
	}
//	cout<<ans<<" "<<temp<<endl;
	cout<<(((k*(k-1)/2)%mod*ans%mod)%mod+(temp*k)%mod)%mod; 
	return 0;
}