#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
template<ll MOD>
struct ModLL {
    ll val;
    ModLL() :val(0) {}
    ModLL(ll v) : val(v >= 0 ? v % MOD : (MOD - (-v) % MOD) % MOD) {}

    ModLL operator -() const { return ModLL(-val); }

    ModLL& operator +=(const ModLL& r) {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return (*this);
    }
    ModLL operator +(const ModLL& r) const {
        return ModLL(*this) += r;
    }

    ModLL& operator -=(const ModLL& r) {
        val += MOD - r.val;
        if (val >= MOD) val -= MOD;
        return (*this);
    }
    ModLL operator -(const ModLL& r) const {
        return ModLL(*this) -= r;
    }

    ModLL& operator *=(const ModLL& r) {
        val *= r.val;
        if (val >= MOD) val %= MOD;
        return (*this);
    }
    ModLL operator *(const ModLL& r) const {
        return ModLL(*this) *= r;
    }

    ModLL& operator /=(const ModLL& r) {
        (*this) *= r.inv();
        return (*this);
    }
    ModLL operator /(const ModLL& r) const {
        return ModLL(*this) /= r;
    }

    bool operator ==(const ModLL& r) {
        return val == r.val;
    }
    bool operator !=(const ModLL& r) {
        return val != r.val;
    }

    ModLL pow(ll n) const {
        ll tmp = val;
        ll ret = 1;
        while (n > 0) {
            if (n & 0x01) {
                ret *= tmp;
                ret %= MOD;
            }
            tmp = tmp * tmp;
            tmp %= MOD;
            n >>= 1LL;
        }
        return ModLL(ret);
    }

    ModLL inv() const {
        ll a = val, b = MOD, u = 1, v = 0;
        while (b > 0) {
            ll t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return ModLL(u);
    }

    friend istream& operator >>(istream &is, ModLL<MOD> &r) {
        ll t; is >> t;
        r = ModLL<MOD>(t);
        return is;
    }
    friend ostream& operator <<(ostream &os, const ModLL<MOD> &r) {
        return os << r.val;
    }
};
#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false); 

    ll N, K; cin >> N >> K;
    vl A(N); REP(i, N) cin >> A[i];

    const ll MOD = (ll)1e9 + 7;

    ll cnt = 0;;
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<N; j++) {
            if (A[i] > A[j]) cnt++;
        }
    }
    ModLL<MOD> sum1 = cnt;
    sum1 *= K;
    
    vl A2;
    REP(i, N) A2.push_back(A[i]);
    REP(i, N) A2.push_back(A[i]);

    ll cnt2 = 0;
    for(int i=0; i<N; i++) {
        for(int j=N; j<N*2; j++) {
            if (A2[i] > A2[j]) cnt2++;
        }
    }
    ModLL<MOD> sum2 = cnt2;
    sum2 *= K * (K - 1) / 2;

    ModLL<MOD> ans = sum1 + sum2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384