#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

//配列サイズは1e6まで
//a[i]>a[j] なる i<jの組み合わせを求める
const int NMAX = 1e6+10;
vector<int> T(NMAX,0);
int inversion(vector<int> &A, const int l, const int r) {
  if(r <= l+1) return 0;
  int cnt = 0;
  const int m = (l+r)/2;
  cnt += inversion(A,l,m) + inversion(A,m,r);

  int i = l, j = m, k = 0, c = 0;
  while(i < m && j < r){
    if(A[j] < A[i]) { // 等しい値も転倒数に含む場合は A[j] <= A[i] とする
      T[k++] = A[j++];
      c++;
    }
    else{
      T[k++] = A[i++];
      cnt += c;
    }
  }

  while(i < m){
    T[k++] = A[i++];
      cnt += c;
  }

  while(j < r) T[k++] = A[j++];

  for(int t = l; t < r; ++t) A[t] = T[t-l];

  return cnt;
}

template<int mod = MOD> class modint{
  private:
    int mMOD = mod, mVal;
  public:
    constexpr modint( int v = 0) noexcept : mVal(v % mMOD) {
      if(mVal < 0) mVal += mMOD;
    }
    
    constexpr int getMOD() {return mMOD;}
    
    constexpr modint operator- () const noexcept {
      return mVal ? mMOD - mVal : 0;
    }
    
    constexpr modint operator + (const modint& r) const noexcept {
      return modint(*this) += r;
    }
    
    constexpr modint operator - (const modint &r) const noexcept {
      return modint(*this) -= r;
    }
    
    constexpr modint operator * (const modint &r) const noexcept {
      return modint(*this) *= r;
    }
    
    modint operator / (const modint &r) const noexcept {
      return modint(*this) /= r;
    }
    
    constexpr modint& operator += (const modint &r) noexcept {
      mVal += r.mVal;
      if(mVal > mMOD) mVal -= mMOD;
      return *this;
    }
    
    constexpr modint& operator -= (const modint &r) noexcept {
      mVal -= r.mVal;
      if(mVal < 0) mVal += mMOD;
      return *this;
    }
    
    constexpr modint& operator *= (const modint &r) noexcept {
      mVal = mVal * r.mVal % mMOD;
      return *this;
    }
    
    modint& operator /= (const modint& r) noexcept {
      int a = r.mVal, b = mMOD, u = 1, v = 0;
      while(b){
        int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
      }
      mVal = mVal * u % mMOD;
      if(mVal < 0) mVal += mMOD;
      return *this;
    }
    
    constexpr bool operator == (const modint& r) const noexcept {
      return this->mVal == r.mVal;
    }
    
    constexpr bool operator != (const modint& r) const noexcept {
      return this->mVal != r.mVal;
    }
    
    constexpr bool operator > (const modint& r) const noexcept {
      return this->mVal > r.mVal;
    }
    
    constexpr bool operator < (const modint& r) const noexcept {
      return this->mVal < r.mVal;
    }
    
    constexpr bool operator >= (const modint& r) const noexcept {
      return this->mVal >= r.mVal;
    }
    
    constexpr bool operator <= (const modint& r) const noexcept {
      return this->mVal <= r.mVal;
    }
    
    friend ostream& operator << (ostream &os, const modint& x) noexcept {
      return os << x.mVal;
    }
    
    friend istream& operator >> (istream &is, modint& x) noexcept {
      return is >> x.mVal;
    }
    
    constexpr operator int() const noexcept {
      return mVal;
    }
    
    constexpr modint operator + (const int& r) const noexcept {
      return modint(*this) += r;
    }
    
    constexpr modint operator - (const int &r) const noexcept {
      return modint(*this) -= r;
    }
    
    constexpr modint operator * (const int &r) const noexcept {
      return modint(*this) *= r;
    }
    
    modint operator / (const int &r) const noexcept {
      return modint(*this) /= r;
    }
    
    constexpr modint& operator += (const int &r) noexcept {
      mVal += r;
      if(mVal > mMOD) mVal -= mMOD;
      return *this;
    }
    
    constexpr modint& operator -= (const int &r) noexcept {
      mVal -= r;
      if(mVal < 0) mVal += mMOD;
      return *this;
    }
    
    constexpr modint& operator *= (const int &r) noexcept {
      mVal = mVal * r % mMOD;
      return *this;
    }
    
    modint& operator /= (const int& r) noexcept {
      int a = r, b = mMOD, u = 1, v = 0;
      while(b){
        int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
      }
      mVal = mVal * u % mMOD;
      if(mVal < 0) mVal += mMOD;
      return *this;
    }
    
    constexpr bool operator == (const int& r) const noexcept {
      return this->mVal == r;
    }
    
    constexpr bool operator != (const int& r) const noexcept {
      return this->mVal != r;
    }
    
    constexpr bool operator > (const int& r) const noexcept {
      return this->mVal > r;
    }
    
    constexpr bool operator < (const int& r) const noexcept {
      return this->mVal < r;
    }
    
    constexpr bool operator >= (const int& r) const noexcept {
      return this->mVal >= r;
    }
    
    constexpr bool operator <= (const int& r) const noexcept {
      return this->mVal <= r;
    }
};

using mint = modint<MOD>;//MODを入力

constexpr mint modpow(const mint &a, int n) noexcept {
  if(n == 0) return 1;
  auto t = modpow(a, n / 2);
  t = t * t;
  if(n & 1) t = t * a;
  return t;
}

mint modconv(mint n,mint r) noexcept {
  if(n < r) return 0;
  else{
    mint res = 1;
    for(int i = 0; i < r; i++){
      res *= n - i;
    }
    for(int i = 0; i < r; i++){
      res /= r - i;
    }
  return res;
  }
}


signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  mint n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  mint inv = inversion(a, 0, a.size());

  mint inv2 = 0;
  REP(i, n) REP(j, n){
    if(i != j && a[i] < a[j]){
      inv2 += 1;
    }
  }

  cout << inv * k + inv2 * k * (k - 1ll) / 2ll << endl;

  return 0;
}

Measured memory_bytes: 8064