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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

enum eps = 1e-9;

enum mod = 1_000_000_007L;

struct ModInt {
    long x = 0;

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

    long powmod(long x, long y) {
        return y > 0 ? powmod(x, y >> 1)^^2 % mod * x^^(y & 1) % mod : 1L;
    }

    void opAssign(long x) {
        x = x % mod;
        if (x < 0) x += mod;
    }

    ModInt opBinary(string op)(const ModInt rhs){
        auto lhs = this;

        static if (op == "+") {
            lhs.x += rhs.x;
            if (lhs.x >= mod) lhs.x -= mod;
            return lhs;
        }
        static if (op == "-") {
            lhs.x -= rhs.x;
            if (lhs.x < 0) lhs.x += mod;
            return lhs;
        }
        static if (op == "*") {
            (lhs.x *= rhs.x) %= mod;
            return lhs;
        }
        static if (op == "/") {
            (lhs.x *= powmod(rhs.x, mod - 2)) %= mod;
            return lhs;
        }
    }

    ModInt opBinary(string op)(long rhs){
        auto lhs = this;

        static if (op != "^^") {
            rhs %= mod;
            if (rhs < 0) rhs += mod;
        }

        static if (op == "+") {
            lhs.x += rhs;
            if (lhs.x >= mod) lhs.x -= mod;
            return lhs;
        }
        static if (op == "-") {
            lhs.x -= rhs;
            if (lhs.x < 0) lhs.x += mod;
            return lhs;
        }
        static if (op == "*") {
            (lhs.x *= rhs) %= mod;
            return lhs;
        }
        static if (op == "/") {
            (lhs.x *= powmod(rhs, mod - 2)) %= mod;
            return lhs;
        }
        static if (op == "^^") {
            lhs.x = powmod(lhs.x, rhs);
            return lhs;
        }
    }

    bool opEquals(ModInt a, ModInt b) {
        return a.x == b.x;
    }

    bool opEquals(T)(const T rhs) {
        long x = rhs % mod;
        if (x < 0) x += mod;
        return this.x == x;
    }

    void opOpAssign(string op)(const ModInt rhs) {
        static if (op == "+") {
            this.x += rhs.x;
            if (this.x >= mod) this.x -= mod;
        }
        static if (op == "-") {
            this.x -= rhs.x;
            if (this.x < 0) this.x += mod;
        }
        static if (op == "*") {
            (this.x *= rhs.x) %= mod;
        }
        static if (op == "/") {
            (this.x *= powmod(rhs.x, mod - 2)) %= mod;
        }
    }

    void opOpAssign(string op)(long rhs) {
        rhs %= mod;
        if (rhs < 0) rhs += mod;

        static if (op == "+") {
            this.x += rhs;
            if (this.x >= mod) this.x -= mod;
        }
        static if (op == "-") {
            this.x -= rhs;
            if (this.x < 0) this.x += mod;
        }
        static if (op == "*") {
            (this.x *= rhs) %= mod;
        }
        static if (op == "/") {
            (this.x *= powmod(rhs, mod - 2)) %= mod;
        }
    }

    string toString() {
        import std.conv : to;
        return x.to!string;
    }
}

unittest {
    enum mod = 1_000_000_007L;

    auto a = ModInt(2);
    auto b = ModInt(3);

    assert(a + b == 5);
    assert(a - b == mod - 1);
    assert(a * b == 6);

    assert(a + 8 == 10);
    assert(a - 1 == 1);
    assert(a * 7 == 14);

    ModInt c = 8;
    assert(c == 8);
}

void main() {
    int N, K;
    scan(N, K);
    auto a = readln.split.to!(int[]);

    auto c = new int[](2000 + 1);

    ModInt inv;
    foreach_reverse (i ; 0 .. N) {
        foreach (j ; i + 1 .. N) {
            if (a[i] > a[j]) inv += 1;
        }
        c[a[i]]++;
    }

    foreach (i ; 1 .. 2000 + 1) {
        c[i] += c[i - 1];
    }

    ModInt ans = inv * K;

    foreach (i ; 1 .. 2000 + 1) {
        ans += (c[i] - c[i - 1]) * c[i - 1] * (1L * K * (K - 1) / 2);
    }

    writeln(ans);
}





void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
