#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, n)    for (int i = 0  ; i <  (n); ++i)
#define for1n(i, n)   for (int i = 1  ; i <= (n); ++i)
#define for1(i, n)    for (int i = 1  ; i <  (n); ++i)
#define forn(i, n)    for (int i = 0  ; i <= (n); ++i)
#define forx(i, n, x) for (int i = (x); i <  (n); ++i)

#define mod 1000000007LL

using namespace std;

class llm{
    long long l;
    static std::unordered_map<long long, llm> inv;

public:
    llm(long long m = 0LL) : l((m % mod >= 0)?(m % mod):(m % mod + mod)) {};

    llm inverse() const {
        if(inv.find(l) == inv.end()){
            llm x = pow(mod - 2);
            inv.emplace(l, x);
            return x;
        }
        return inv[l];
    }

    llm pow (long long i) const {
        if (i < 0)  return inverse().pow(-i);
        if (i == 0) return 1;
        long long int x = pow(i / 2) % mod;
        if (i % 2 == 0) {
            return x * x % mod;
        }else {
            return x * x * l % mod;
        }
    }

    llm operator= (llm m) {l = m.l; return *this;}

    llm operator<< (long long i) const {return pow( i);};
    llm operator>> (long long i) const {return pow(-i);}

    llm operator+ (llm m)       const {return llm(l + m.l);}
    llm operator+ (int m)       const {return llm(l + (m % mod));}
    llm operator+ (long m)      const {return llm(l + (m % mod));}
    llm operator+ (long long m) const {return llm(l + (m % mod));}

    llm operator- (llm m)       const {return llm(l - m.l);}
    llm operator- (int m)       const {return llm(l - (m % mod));}
    llm operator- (long m)      const {return llm(l - (m % mod));}
    llm operator- (long long m) const {return llm(l - (m % mod));}

    llm operator* (llm m)       const {return llm(l * m.l);}
    llm operator* (int m)       const {return llm(l * (m % mod));}
    llm operator* (long m)      const {return llm(l * (m % mod));}
    llm operator* (long long m) const {return llm(l * (m % mod));}

    llm operator/ (llm m)       const {return llm((*this) * m.inverse() % mod);}
    llm operator/ (int m)       const {return llm(l * llm(m).inverse()) % mod;}
    llm operator/ (long m)      const {return llm(l * llm(m).inverse()) % mod;}
    llm operator/ (long long m) const {return llm(l * llm(m).inverse()) % mod;}

    long long operator++ (void) {return l = (l + 1) % mod;}
    long long operator++ (int)  {long long tmp = l; ++(*this); return tmp;}

    long long operator-- (void) {return l = (l - 1) % mod;}
    long long operator-- (int)  {long long tmp = l; --(*this); return tmp;}

    llm operator+ (void) const {return llm( l);}
    llm operator- (void) const {return llm(-l);}

    template<typename T> llm operator+= (T m) {return *this = *this + m;}
    template<typename T> llm operator-= (T m) {return *this = *this - m;}
    template<typename T> llm operator*= (T m) {return *this = *this * m;}
    template<typename T> llm operator/= (T m) {return *this = *this / m;}

    operator long long() {return l;}

    friend istream &operator>>(istream &stream, llm &m);

};

unordered_map<long long, llm> llm::inv;

std::istream& operator>> (istream &stream, llm &m) {
   long long tmp;
    stream >> tmp;
    m.l = tmp % mod;
    return stream;
}

typedef long long ll;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll> ,greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;

int main(void){

    int N;
    llm K;
    cin >> N >> K;
    int a[2000]={};

    for0(i, N){
        cin >> a[i];
    }

    pair<llm, llm> p[2000];

    for0(i, N){
        p[i].first=0;           // all
        p[i].second=0;          // after
    }

    for0(i, N){
        for0(j, N){
            if (a[i] > a[j]) {
                ++p[i].first;
                if (i < j) {
                    ++p[i].second;
                }
            }
        }
        // p[i].first%=mod;
        // p[i].second%=mod;
    }

    llm result = 0;

    for0(i, N){
        // result = (result + (p[i].second *K));
        // result = ((p[i].first  * (((long long)K * ((long long)K-1))/2))  + result);

        // // result = (result + (p[i].second *K %mod)) %mod;
        // // result = ((p[i].first  * ((K-1) *K/2 % mod)) %mod  + result) % mod;
        result = ((p[i].first * (K-1) + 2 * p[i].second) * K / 2 + result) % mod;
    }

    cout << result;

    return 0;
}


Measured memory_bytes: 512