import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto n = s[0];
    auto k = s[1].to!long;
    auto A = readln.split.map!(to!int).array;

    auto cnt = new long[](2002);
    foreach (a; A) (cnt[a-1] += 1) %= MOD;
    foreach_reverse (i; 1..2002) (cnt[i-1] += cnt[i]) %= MOD;

    auto K = k * (k - 1) % MOD * powmod(2, MOD-2, MOD) % MOD;
    long ans = 0;
    foreach (i; 1..2002) (ans += K * cnt[i] % MOD) %= MOD;

    foreach (i; 0..n) {
        foreach (j; i+1..n) {
            if (A[i] > A[j]) {
                (ans += k) %= MOD;
            }
        }
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}
