function Main(input) {
    input = input.split("\n");
    const MOD = 1000000007;
    var nk = input[0].split(' ');
    var n = parseInt(nk[0], 10);
    var k = parseInt(nk[1], 10);
    var a = input[1].split(' ');
    a = a.map(str => parseInt(str, 10));
    var count = 0;

    for(var i = 0;i < n;i++){
        var abef = a.filter(function(v,index){return v<a[i] && index < i});
        var lbef = abef.length;
        var aaft = a.filter(function(v,index){return v<a[i] && index > i});
        var laft = aaft.length;
        //count += laft + (lbef + laft) * (k - 1);
        var kb = (k * (k - 1) / 2) % MOD;
        var ka = (k * (k + 1) / 2) % MOD;
        var bef = (lbef * kb) % MOD;
        var aft = (laft * ka) % MOD;
        count += (bef + aft) % MOD;
    }

    console.log(count % MOD);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));