#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define ppi pair<int,pair<int,int> >
#define fr first
#define sc second
#define PI acos(-1)
#define mp make_pair

const int mod = 1e9 + 7;

using namespace std;

#define sim template < class c

#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//
//int n;
//vector<ll>v;
//vector<ll>pr;
//int p[40000];
//bool isprime(ll x){
//    for(int i = 0;pr[i]*pr[i]<=x;i++)
//        if(x % pr[i] == 0)return 0;
//    return 1;
//}
//ll sum (int x){
//    ll a = 0;
//    for(int i = 0;i<n;i++)a += abs(v[i] - x);
//    return a;
//}
//for(int i = 2;i<40000;i++)if(p[i] == 0){
//        pr.push_back(i);
//        for(int j = i + i;j<40000;j+=i)p[i] = 1;
//    }
//    cin >> n;
//    for(int i = 0;i<n;i++)
//    {
//        int x; cin >> x;
//        v.push_back(x);
//    }
//    sort(v.begin(),v.end());
//    ll ans = 1e18;
//    if(n % 2){
//        int i = n / 2;
//        int x = v[i];
//        int y = x;
//        while(!isprime(y))y++;
//        ans = min(ans , sum(y));
//        y = x;
//        while(y > 1 && !isprime(y))y--;
//        if(isprime(y))
//            ans = min(ans , sum(y));
//    }
//    else{
//        int i = n / 2 , j = n / 2 - 1;
//        int x1 = v[i],x2 = v[j];
//        while(!isprime(x1))x1++;
//        ans = min(ans , sum(x1));
//        x1++;
//        while(!isprime(x1))x1++;
//        ans = min(ans , sum(x1));
//
//        x1 = v[i];
//        while(x1 > 0 && !isprime(x1))x1--;
//        if(isprime(x1))ans = min(ans , sum(x1));
//        x1--;
//        while(x1 > 0 && !isprime(x1))x1--;
//        if(isprime(x1))ans = min(ans , sum(x1));
//
//
//
//        while(x2 > 1 && !isprime(x2))x2--;
//        if(isprime(x2))
//            ans = min(ans , sum(x2));
//        x2--;
//
//        while(x2 > 1 && !isprime(x2))x2--;
//        if(isprime(x2))
//            ans = min(ans , sum(x2));
//
//    }
//    cout << ans << endl;

ll power(int x,int u){
   if(!u)return 1;
   ll temp = power(x,u / 2);
   temp = temp * temp % mod;
   if(u % 2)temp = temp * x % mod;
   return temp;
}
ll inv(ll x , ll y){
    return x * power(y , mod - 2) % mod;
}
int main()
{
    ll n,k; cin >> n >> k;
    ll a[2020];
    for(int i = 0;i<n;i++)
        cin >> a[i];
    ll ans = 0;
    for(int i = 0;i<n;i++){
      ll cnt = 0;
      for(int j = i + 1; j < n;j++)cnt += (a[i] > a[j]);
      ll res = cnt * inv(k * (k + 1) % mod , 2) % mod;
      ans = (ans + res) % mod;

      res = 0,cnt = 0;
      for(int j = i - 1;j>=0;j--)cnt += (a[i] > a[j]);
      res = cnt * inv((k-1)*(k)% mod , 2) % mod;
      ans = (ans + res) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256