#include<bits/stdc++.h>

const int MOD = 1e9 + 7;

int a[2005];
int n, k;

int main()
{
	scanf("%d%d", &n, &k);
	
	long long p = (long long)(k + 1) * k / 2;
	long long q = (long long)k * (k - 1) / 2;
	p %= MOD, q %= MOD;
	
	long long ans = 0;
	for(int i = 1; i <= n; i++) 
	{
		scanf("%d", &a[i]);
		for(int j = 1; j < i; j++)
			if (a[i] > a[j])
				ans += q;
			else if (a[i] < a[j])
				ans += p;
		ans %= MOD;
	}
	printf("%d\n", (int)ans);
	
	return 0;
}