// OURL: https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

#ifdef LOCAL
#include "pprint.hpp"
pprint::PrettyPrinter printer;
#define debug(...) cerr << "[L" << __LINE__ << ":" <<#__VA_ARGS__ << "]: ", printer.print(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<int MOD>
struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) val += MOD;
  }
  constexpr int getmod() {return MOD;}
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val>=MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val>=MOD) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
#ifdef LOCAL
  printer.compact(true);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n,k;
  cin >> n >> k;
  auto as = make_v<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> as[i];
  }
  auto fs = make_v<int>(n);
  auto bs = make_v<int>(n);
  for (int i = 0; i < n; ++i) {
    int a = as[i];
    for (int j = 0; j < i; ++j) {
      if(as[j] < a) fs[i]++;
    }
    for (int j = i+1; j < n; ++j) {
      if(as[j] < a) bs[i]++;
    }
  }
  mint ans = 0;

  debug(fs, bs);
  for (int i = 0; i < n; ++i) {
    mint x = fs[i]+bs[i];
    mint y = bs[i];
    mint t = x * ((k-1)*(k)/2) + y*k;
    ans += t;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256