#include <cstdio>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int N, A[2000]; ll K;
int main() {
  scanf("%d %ld", &N, &K);
  for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
  ll localT = 0LL, localL = 0LL;
  for(int l = 0; l < N-1; ++l) {
    for(int r = l; r < N; ++r) {
      if(A[l] > A[r]) ++localT;
      if(A[l] != A[r]) ++localL;
    }
  }
  ll sum = localT*K%MOD;
  if(K%2 == 0) sum += (K/2*(K-1))%MOD*localL;
  else sum += ((K-1)/2*(K-2)+K-1)%MOD*localL;
  printf("%ld\n", sum%MOD);
}