#include <iostream>
#include <cstdio>
using namespace std;

typedef long long ll;
ll M = 1e9 + 7;
ll n, m, s, a[2005];
ll f(ll p) {
	return (p * (p - 1)) / 2;
}
int main()
{
	ll i, j;
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (a[i] > a[j]) {
				s = (s + f(m)) % M;
				if (i < j) s = (s + m) % M;
			}
		}
	}
	cout << s;
    return 0;
}
