#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define VEC2(type, name, dim0, dim1, init_val) vector<vector<type>> name(dim0, vector<type>(dim1, init_val))
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

#define REP(name, start, end) for(ll name = (start); (name) < (end); ++(name))
#define REPR(name, end, start) for(ll name = (start - 1); (name) >= (end); --(name))
#define ALL(iterable) (iterable).begin(), (iterable).end()

class LongLongMod {
private:
	long long value;
	long long mod;
public:
	LongLongMod(long long v, long long m) : value(v% m), mod(m) {};
	LongLongMod(long long v) : LongLongMod(v, 1000000007LL) {};
	long long getValue() { return value; }
	long long getMod() { return mod; }
	operator long long() { return value; }
	inline bool operator == (const LongLongMod& rhs) const { return (value == rhs.value && mod == rhs.mod); }
	inline bool operator != (const LongLongMod& rhs) const { return !(*this == rhs); }
	inline bool operator > (const LongLongMod& rhs) const { return (value > rhs.value && mod == rhs.mod); }
	inline bool operator < (const LongLongMod& rhs) const { return !(*this > rhs) && !(*this == rhs); }
	inline bool operator >= (const LongLongMod& rhs) const { return !(*this < rhs); }
	inline bool operator <= (const LongLongMod& rhs) const { return !(*this > rhs); }

	inline LongLongMod& operator = (const long long& rhs) { value = rhs % mod; return *this; }
	inline LongLongMod operator + (const long long& rhs) const { return LongLongMod((value + rhs) % mod, mod); }
	inline LongLongMod& operator += (const long long& rhs) { value = (value + rhs) % mod; return *this; }
	inline LongLongMod operator - (const long long& rhs) const { return LongLongMod((value + mod - rhs) % mod, mod); }
	inline LongLongMod& operator -= (const long long& rhs) { value = (value + mod - rhs) % mod; return *this; }
	inline LongLongMod operator * (const long long& rhs) const { return LongLongMod(((value % mod) * (rhs % mod)) % mod, mod); }
	inline LongLongMod& operator *= (const long long& rhs) { value = ((value % mod) * (rhs % mod)) % mod; return *this; }
	inline LongLongMod operator / (const long long& rhs) const { return LongLongMod(*this * ((LongLongMod)rhs).invert()); }
	inline LongLongMod& operator /= (const long long& rhs) { *this *= ((LongLongMod)rhs).invert(); return *this; }
	inline LongLongMod operator % (const long long& rhs) const { return LongLongMod(value % rhs, rhs); }
	inline LongLongMod& operator %= (const long long& rhs) { value = value % rhs; mod = rhs; return *this; }

	LongLongMod invert() {
		// 逆元 (1/x) : 存在条件 = valueとmodが互いに素
		// memo : mod = 10^9+7(素数)の時, value != 0ならok.
		long long a = value, b = mod, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= mod;
		if (u < 0) u += mod;
		return LongLongMod(u, mod);
	}

	LongLongMod power(long long exp) {
		// べき乗
		long long a = value, res = 1;
		while (exp > 0) {
			if (exp & 1) res = res * a % mod;
			a = a * a % mod;
			exp >>= 1;
		}
		return res;
	}

	LongLongMod factorial() {
		// 階乗
		LongLongMod res(1LL, mod);
		for (long long i = value; i > 0; --i)res *= i;
		return res;
	}
};

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);
	IN(ll, k);
	IN_V(ll, als, n);

	LongLongMod cnt(0);
	vector<pair<ll, ll>> lessCount(n, make_pair(0, 0));
	REP(i, 0, n) {
		REP(j, 0, n) {
			if (als[i] > als[j]) {
				if (j < i)++lessCount[i].first;
				else ++lessCount[i].second;
			}
		}
	}

	LongLongMod num((k - 1)* k / 2);
	REP(i, 0, n) {
		cnt += (LongLongMod(lessCount[i].first + lessCount[i].second) * num) + (LongLongMod(lessCount[i].second) * k);
	}

	cout << cnt.getValue() << endl;
	return 0;
}

Measured memory_bytes: 256