#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}
 
template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

// Mint {{{
template <i64 MOD>
class ModInt {
  i64 value;
public:
  inline ModInt(const ModInt& other) noexcept : value(other.value) {}
  inline ModInt(i64 value = 0) noexcept :
    value((value >= MOD) ? value % MOD : (value < 0) ? (value + MOD) % MOD : value) {}

  inline ModInt inv() const noexcept { return pow(value, MOD - 2); }

  inline ModInt& operator+=(const ModInt& other) noexcept {
    value = (value + other.value) % MOD; return *this;
  }

  inline ModInt& operator-=(const ModInt& other) noexcept {
    value = (MOD + value - other.value) % MOD; return *this;
  }

  inline ModInt& operator*=(const ModInt& other) noexcept {
    value = (value * other.value) % MOD; return *this;
  }

  inline ModInt& operator/=(const ModInt& other) noexcept {
    value = (value * other.inv().value) % MOD; return *this;
  }

  inline ModInt operator+(const ModInt& other) noexcept { return ModInt(*this) += other; }
  inline ModInt operator-(const ModInt& other) noexcept { return ModInt(*this) -= other; }
  inline ModInt operator*(const ModInt& other) noexcept { return ModInt(*this) *= other; }
  inline ModInt operator/(const ModInt& other) noexcept { return ModInt(*this) /= other; }

  inline bool operator==(const ModInt& other) noexcept { return value == *other; }
  inline bool operator!=(const ModInt& other) noexcept { return value != *other; }

  template <class _int>
  explicit inline operator _int() const noexcept { return static_cast<_int>(value); }

  friend ostream& operator<<(ostream &os, const ModInt& other) noexcept {
    os << other.value; return os;
  }

  friend istream& operator>>(istream &is, const ModInt& other) noexcept {
    is >> other.value; return is;
  }

  static constexpr inline ModInt power(i64 n, i64 p) noexcept {
    i64 ret = 1;
    for (; p > 0; p >>= 1) {
      if (p & 1) ret = (ret * n) % MOD;
      n = (n * n) % MOD;
    }
    return ret;
  }
};

using Mint = ModInt<MOD>;
// }}}

i64 sigma(i64 n) { return n * (1 + n) / 2; }

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(i64, N, K);

  vector<i64> a(N);
  rep(i, N) {
    IN(a[i]);
  }

  Mint c1 = 0, c2 = 0;
  rep(i, N) {
    rep(j, i) {
      if (a[j] > a[i]) c1 += 1;
    }
  }

  rep(i, N) {
    rep(j, N) {
      if (a[j] > a[i]) c2 += 1;
    }
  }

  c1 *= K;
  c2 *= sigma(K - 1);

  OUTL(c1 + c2);

  return 0;
}


Measured memory_bytes: 256