#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e9+7;
int main(){
	ll n,k;
	cin >> n >> k;
	ll m=(((k+1)*k)/2)%N;
	ll p =((k*(k-1))/2)%N;
	ll a[n];
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	ll cnt = 0;
	for(int i=0;i<n;i++){
		ll sum=0;
		ll ans=0;
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j])sum++;} 
		sum%=N;
		cnt+=(sum*(m%N))%N;
		for(int j=i-1;j>=0;j--){
			if(a[i]>a[j])ans++;
		}
		ans%=N;
		cnt+=(ans*(p%N))%N;
	}
	cout << cnt%N << endl;
	return 0;
}