// B - Kleene Inversion
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

int main(){
	ll N,K; cin>>N>>K;
	vector<ll> A(N);
	ll L = 0, M = 0;
	for(int i=0; i<N; i++){
		cin>>A[i];
		for(int j=i-1; j>=0; j--) if(A[i]<A[j]) L++;
	}

	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++) if(i!=j && A[i]>A[j]) M++;

	ll KC2 = K*(K-1)/2 % MOD;
	ll a = L * K % MOD;
	ll b = M * KC2 % MOD;
	cout<< (a+b) % MOD << endl;
}