#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;
public:
    llm(long long int l = 0): l(l % mod){assert(this->l<mod);};

    llm& operator=(llm m)      {l = m.l;     return *this;}
    llm& operator=(int i)      {l = i % mod; return *this;}
    llm& operator=(long i)     {l = i % mod; return *this;}
    llm& operator=(long long i){l = i % mod; return *this;}

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

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

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

    // llm operator/(llm m)      {return llm(l / m.l);}
    llm operator/(int m)      {assert(mod%m!=0); return llm(l / m);}
    llm operator/(long m)     {assert(mod%m!=0); return llm(l / m);}
    llm operator/(long long m){assert(mod%m!=0); return llm(l / m);}

    // llm operator%(llm m)      {return llm(l % m.l);}
    llm operator%(int m)      {return llm(l % m);}
    llm operator%(long m)     {return llm(l % m);}
    llm operator%(long long m){return llm(l % m);}

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

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


    operator long long(){
        // cout << "l: " << l << "\n";
        return l;
    }

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

// operator int(){return l;}
};

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;

#define llm ll

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  * ((K-1) *K/2))  + result);

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

    cout << result;

    return 0;
}


Measured memory_bytes: 256