void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], k = tmp[1];
    long[] a = readln.split.to!(long[]);

    long mod = 10 ^^ 9 + 7;
    long[] l = new long[n], r = new long[n];
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. n)
        {
            if (a[i] > a[j])
            {
                if (i > j) ++l[i];
                else ++r[i];
            }
        }
    }

    long lsum = k * (k - 1) / 2 % mod;
    long rsum = k * (k + 1) / 2 % mod;
    long result;
    foreach (i; 0 .. n)
    {
        long total = (l[i] * lsum) % mod + (r[i] * rsum) % mod;
        total %= mod;
        result = (result + total) % mod;
    }

    result.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;