function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var A = input[1].split(" ").map(i => parseInt(i));
  var mod = Math.pow(10,9)+7;
  var ans1 = 0;
  var ans2 = 0;
  for(var i=1;i<N;i++){
    for(var j=0;j<N-i;j++){
      if(A[j]>A[j+i]){
        ans1++;
      }
    }
  }
  A.push(...A);
  for(var i=1;i<N*2;i++){
    for(var j=0;j<N*2-i;j++){
      if(A[j]>A[j+i]){
        ans2++;
      }
    }
  }
  if(K%2==0){
    var ans = (((ans1%mod)*K)%mod + ((((ans2-(ans1*2)%mod)%mod * (K/2)%mod)%mod)*(K-1))%mod)%mod;
  }else{
    var ans = (((ans1%mod)*K)%mod + ((((ans2-(ans1*2)%mod)%mod * ((K-1)/2)%mod)%mod)*(K))%mod)%mod;
  }


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));