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 uint MOD = 10^^9 + 7;
alias mint = ModInt!MOD;

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

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

    auto K = mint(k) * mint(k-1) / mint(2);
    auto ans = K * cnt[1..2002].sum;

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

    ans.writeln;
}

struct ModInt(uint mod) {
    import std.conv : to;

    uint n;

    this(int n) {
        this.n = (n % mod + mod) % mod;
    }

    this(long n) {
        this.n = (n % mod + mod) % mod;
    }

    private this(uint n) {
        this.n = n;
    }

    string toString() const {
        return to!string(this.n);
    }

    private uint normilize(uint n) const {
        return n < mod ? n : n - mod;
    }

    private ModInt pow(uint n, long x) const {
        long ret = 1;
        long a = n;
        while (x) {
            if (x & 1) ret = ret * a % mod;
            a = a * a % mod;
            x >>= 1;
        }
        return ModInt(to!ulong(ret));
    }

    ModInt opBinary(string op : "+")(ModInt rhs) const {
        return ModInt(normilize(n + rhs.n));
    }

    ModInt opBinary(string op : "-")(ModInt rhs) const {
        return ModInt(normilize(n + mod - rhs.n));
    }

    ModInt opBinary(string op : "*")(ModInt rhs) const {
        return ModInt(to!uint(to!long(n) * rhs.n % mod));
    }

    ModInt opBinary(string op : "/")(ModInt rhs) const {
        return this * pow(rhs.n, mod-2);
    }

    ModInt opBinary(string op : "^^")(ModInt rhs) const {
        return pow(this.n, rhs.n);
    }

    ModInt opBinary(string op, T)(T rhs) const {
        ModInt mod_rhs = ModInt(rhs);
        return opBinary!op(mod_rhs);
    }

    ModInt opOpAssign(string op)(ModInt rhs) {
        return mixin ("this=this"~op~"rhs");
    }
}
