#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

const int mod = 1000000007;

struct mint {
    ll x;
    mint (ll x = 0) : x(x % mod) {}
    mint& operator += (const mint a) { // コンストラクタの、modで割った余りがくる
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -= (const mint a) {
        if ((x += -a.x + mod) >= mod) x -= mod;
        return *this;
    }
    mint& operator *= (const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator + (const mint a) const {
        mint res(*this);
        return res += a; // ?
    }
    mint operator - (const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator * (const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const { // mint(a).pow(t) tは余りとったりしたらあかん
        if (t == 0) return 1;
        mint a = pow(t >> 1); // 再帰
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    // 逆元
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator /= (const mint a) { // invを利用
        return (*this) *= a.inv();
    }
    mint operator / (const mint a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream &operator<<(ostream &s, mint a) { return s << a.x; }
};



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    int n, k;
    cin >> n >> k;
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    
    int table[2001] = {0};
    int table2[2001] = {0};
    rep(i, n) {
        int cnt = 0;
        rep(j, i) {
            if (b[j] < b[i]) cnt++;
        }
        table[i] = cnt;
        cnt = 0;
        rep3(j, i + 1, n) {
            if (b[j] < b[i]) cnt++;
        }
        table2[i] = cnt;
    }
    // outa(table, n);
    // outa(table2, n);
    
    mint ans = 0;
    rep(i, n) {
        mint tmp = 0;
        tmp += (ll)(k - 1) * (table[i] + table2[i]);
        tmp /= 2;
        tmp += table2[i];
        tmp *= k;
        
        
        
        
        ans += tmp;
    }
    out(ans);
    /*
    vector<pii> a(n);
    rep(i, n) a[i].F = b[i]; // value
    rep(i, n) a[i].S = i; // index
    
    sort(all(a), greater<pii>());
    
    int n2;
    {
        int now = 1;
        rep(i, n) {
            a[i].F = now;
            if (i && a[i].F == a[i - 1].F) {}
            else {
                now++;
            }
        }
        now = 0;
        rep3(i, 1, n) {
            if (a[i].F == a[i - 1].F) now++;
        }
        // outp(a, n);
        n2 = n - now;
    }
    
    
    
    int table[2001] = {0};
    rep(i, n) table[a[i].S] = a[i].F;
    
    outa(table, n);
    
    int table2[2001] = {0}; // 手前にいくつ
    rep(i, n) {
        int cnt = 0;
        rep(j, i) {
            if (b[j] < b[i]) cnt++;
        }
        table2[i] = cnt;
    }
    outa(table2, n);
    
    mint ans = 0;
    rep(i, n) {
        mint tmp = 0;
        tmp += (ll)(k - 1) * (n2 - table[i]);
        tmp /= 2;
        tmp += n2 - table[i] - table2[i];
        tmp *= k;
        
        
        
        
        ans += tmp;
    }
    out(ans);
     */
}


Measured memory_bytes: 256