import CoreFoundation
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let n = arr[0]
let k = arr[1]

let a=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var twoa : [Int] = []

var i = 0
var j = 0

var o = 0
var tno = 0

for i in 0..<n {
  for j in 0..<n {
    if( a[i] > a[j] ){
      o += 1
    }
  }
}

for i in 0..<n {
  //var tmp = a[i%(n)]
  for j in i+1..<n{
    if( a[i] > a[j] ){
      tno += 1
    }
  }
}

var limit : Int = Int( pow( Double(10), Double(9) ) ) + 7

//var test : Int = 998244353 * 998244352 / 2 
//test = test * tno
//print( test, tno )
let K = (k * (k-1) / 2) % limit
var ans = 0
ans += (o%limit * K) % limit + (tno%limit * k) % limit
var zensya = ( ( o % limit ) * k )
var kousya = ( ( ( k * ( k - 1 ) ) / 2 ) ) % limit
kousya = kousya * tno
print( ans % limit )
//print( ( zensya + kousya ) % limit )