#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;

 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

template<int mod>
struct ModInt {
    int x;
 
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
 
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
 
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
 
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
 
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
 
const int mod = 1e9 + 7;
using modint = ModInt<mod>;




int main(){
  ll N,K;
  cin >> N >> K;
  
  vector<ll> S1(N);
  vector<ll> S2(N);
  
  vector<ll> A(N);
  
  rep(i,N){
    ll a;
    cin >> A[i];
  }
  
  rep(i,N){
    ll count1 = 0;
    ll count2 = 0;
    rep(j,N){
      if(A[i]>A[j]){
        count1 += 1;
        if(j>i)count2 += 1;
      }
    }
    S1[i] = count1;
    S2[i] = count2;
  }
  
  ll sum1 = 0;
  ll sum2 = 0;
  
  for(ll n: S1){
    sum1 += n;
  }
  
  for(ll n: S2){
    sum2 += n;
  }
  
  // ll ans = ( ( (sum2%MOD) * (K%MOD) )%MOD ) + ( (((sum1%MOD)*(((K-1)%MOD)*(K%MOD))%MOD)%MOD)*modinv(2, MOD)%MOD );
  modint ans = 0;
  
  modint s1,s2,k,km1,n2;
  s1 = sum1;
  s2 = sum2;
  k = K;
  km1 = K-1;
  n2 = 2;

  ans = ( ( sum2 * K )%mod ) + ( ((sum1*((K-1)/2*K)%mod)%mod) );
  ans = (s2 * k + s1*km1*k/n2);
  
  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 256