#include <bits/stdc++.h>

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

class modint { private: std::int64_t number; static const std::int64_t modulo; public: static vector<modint> fac; static vector<modint> fac_inv; modint() : number(0) {} modint(const std::uint64_t new_number) { set(new_number); } modint(const modint& m) : number(m.number) {} void set(const std::int64_t new_number) { number = new_number % modulo; if(number < 0) number += modulo; } std::int64_t get() const { return number; } modint operator++(int) { modint ret = *this; ++(*this); return ret; } modint operator--(int) { modint ret = *this; --(*this); return ret; } modint& operator++() { *this += 1; return *this; } modint& operator--() { *this -= 1; return *this; } bool operator!() const noexcept { return !static_cast<bool>(*this); } modint operator+() const { return *this; } modint operator-() const { modint ret(*this);ret.set(-number);return ret;} explicit operator std::int64_t() const noexcept{ return number; } explicit operator bool() const noexcept{ return number != 0; } modint& operator=(const std::int64_t i) { set(i); return *this; } modint operator*=(const modint& m) { set(number * m.number); return *this; } modint operator/=(const modint& m) { *this *= modint::inv(m); return *this; } modint operator%=(const modint& m) { set(number % m.number); return *this; } modint operator+=(const modint& m) { set(number + m.number); return *this; } modint operator-=(const modint& m) { set(number - m.number); return *this; } modint operator*=(const std::int64_t& i) { set(number * i); return *this; } modint operator/=(const std::int64_t& i) { *this /= modint(i); return *this; } modint operator%=(const std::int64_t& i) { set(number % i); return *this; } modint operator+=(const std::int64_t& i) { set(number + i); return *this; } modint operator-=(const std::int64_t& i) { set(number - i); return *this; } modint factorial() const { if(get() < fac.size()) { return fac.at(get()); } std::int64_t ret = static_cast<std::int64_t>(fac.back()); for(std::int64_t i = fac.size(); i <= get(); ++i) { ret = (ret * i) % modulo; } return modint(ret); } static modint pow(const modint& m1, const modint& m2) { std::int64_t base = m1.get(); std::int64_t exponent = m2.get(); std::int64_t ret = 1; while(exponent > 0) { if(exponent & 1) ret = (ret * base) % modulo; base = (base * base) % modulo; exponent >>= 1; } return modint(ret); } static modint inv(const modint& m) { std::int64_t a = m.get(); std::int64_t b = modulo; std::int64_t u = 1; std::int64_t v = 0; std::int64_t aa = a; while(b != 0) { std::int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } modint ret(u); return ret; } static modint nPr(const modint& n, const modint& r); static modint nCr(const modint& n, const modint& r); static void init_factorial(const std::int64_t max_fac_index = 510000); }; const std::int64_t modint::modulo = 1000000007; vector<modint> modint::fac; vector<modint> modint::fac_inv; const modint operator*(const modint& m1, const modint& m2) { return modint(m1) *= m2; } const modint operator/(const modint& m1, const modint& m2) { return modint(m1) /= m2; } const modint operator%(const modint& m1, const modint& m2) { return modint(m1) %= m2; } const modint operator+(const modint& m1, const modint& m2) { return modint(m1) += m2; } const modint operator-(const modint& m1, const modint& m2) { return modint(m1) -= m2; } const modint operator*(const modint& m, const std::int64_t& i) { return modint(m) *= i; } const modint operator/(const modint& m, const std::int64_t& i) { return modint(m) /= i; } const modint operator%(const modint& m, const std::int64_t& i) { return modint(m) %= i; } const modint operator+(const modint& m, const std::int64_t& i) { return modint(m) += i; } const modint operator-(const modint& m, const std::int64_t& i) { return modint(m) -= i; } const modint operator*(const std::int64_t& i, const modint& m) { return modint(i) *= m; } const modint operator/(const std::int64_t& i, const modint& m) { return modint(i) /= m; } const modint operator%(const std::int64_t& i, const modint& m) { return modint(i) %= m; } const modint operator+(const std::int64_t& i, const modint& m) { return modint(i) += m; } const modint operator-(const std::int64_t& i, const modint& m) { return modint(i) -= m; } std::ostream& operator<<(std::ostream& os, const modint m) { os << m.get(); return os; } std::istream& operator>>(std::istream& is, modint& m) { std::int64_t i; is >> i; m.set(i); return is; } bool operator<(const modint& m1, const modint& m2) { return m1.get() < m2.get(); } bool operator>(const modint& m1, const modint& m2) { return m2 < m1; } bool operator<=(const modint& m1, const modint& m2) { return !(m1 > m2); } bool operator>=(const modint& m1, const modint& m2) { return !(m1 < m2); } bool operator==(const modint& m1, const modint& m2) { return !(m1 < m2) && !(m1 > m2); } bool operator!=(const modint& m1, const modint& m2) { return !(m1 == m2); } modint operator^(const modint& m1, const modint& m2) { return modint::pow(m1, m2); }; modint modint::nPr(const modint& n, const modint& r) { init_factorial(); if(n < r) return 0; return fac[n.get()] * fac_inv[n.get() - r.get()]; } modint modint::nCr(const modint& n, const modint& r) { init_factorial(); if(n < r) return 0; return fac[n.get()] * fac_inv[r.get()] * fac_inv[n.get() - r.get()]; } void modint::init_factorial(const std::int64_t max_fac_index) { static bool is_initted = false; if(is_initted) return; is_initted = true; fac = vector<modint>(max_fac_index); fac[0] = fac[1] = 1; for(std::int64_t i = 2; i < max_fac_index; ++i) { fac[i] = fac[i - 1] * i; } fac_inv = vector<modint>(max_fac_index); fac_inv[0] = fac_inv[1] = 1; fac_inv[max_fac_index - 1] = inv(fac[max_fac_index - 1]); for(std::int64_t i = max_fac_index - 2; i >= 0; --i) { fac_inv[i] = fac_inv[i + 1] * (i + 1); } }

int main(int argc, const char* argv[]) {
	ll n, k;
	cin >> n >> k;

	vector<ll> a(n);
	rep(i, n) {
		cin >> a.at(i);
	}

	modint ret = 0;

	rep(i, n) {
		rep(j, n) {
			if(a.at(i) <= a.at(j)) continue;

			if(i < j) {
				ret += k * (k+1) / 2;
			} else {
				ret += k * (k-1) / 2;
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256