#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;


class modint_t {
public:
    modint_t() = default;
    modint_t(int64_t value):value(value % MOD){}

    bool operator<(const modint_t rhs) const { return value < rhs.value; }
    bool operator<=(const modint_t rhs) const { return value <= rhs.value; }
    bool operator>(const modint_t rhs) const { return value > rhs.value; }
    bool operator>=(const modint_t rhs) const { return value >= rhs.value; }

    modint_t operator+(const modint_t rhs) const { return modint_t(value + rhs.value); }
    modint_t operator+=(const modint_t rhs) { return value = (value + rhs.value) % MOD; }
    modint_t operator-(const modint_t rhs) const { return modint_t(MOD + value - rhs.value); }
    modint_t operator-=(const modint_t rhs) { return value = (MOD + value - rhs.value) % MOD; }

    modint_t operator*(const modint_t rhs) const { return modint_t(value * rhs.value); }
    modint_t operator*=(const modint_t rhs) { return value = value * rhs.value % MOD; }
    modint_t operator/(const modint_t rhs) const { return *this * rhs.invert(); }
    modint_t operator/=(const modint_t rhs) { return *this *= rhs.invert(); }

    modint_t square() const { return *this * *this; }
    modint_t power(int64_t y) const
    {
        if(y == 0) return 1;
        else if(y == 1) return *this;
        else if(y % 2 == 0) return this->power(y/2).square();
        else return *this * this->power(y-1);
    }

    modint_t invert() const
    {
        return power(MOD-2);
    }
    
    operator int64_t() const
    {
        return value;
    }
private:
    static const int MOD = 1000000007;
    int64_t value = 0;
};

modint_t factorial(int64_t n)
{
    if(n <= 1) return 1;
    modint_t f = 1;
    for(int64_t i = 1; i <= n; ++i)
    {
        f *= i;
    }
    return f;
}

modint_t permutation(int64_t n, int64_t r)
{
    modint_t p = 1;
    for(int64_t i = n; i > n-r; --i)
    {
        p *= i;
    }
    return p;
}

modint_t combination(int64_t n, int64_t r)
{
    if(r * 2 > n) r = n - r;
    modint_t x = 1;
    modint_t y = 1;
    for(int64_t i = 1; i <= r; ++i)
    {
        x *= n - i + 1;
        y *= i;
    }
    return x / y;
}

modint_t multichoose(int64_t n, int64_t k)
{
    return combination(n + k - 1, k);
}

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}
 
template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}
 
template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}


int main()
{
    int N,K;
    cin >> N >> K;
    auto as = reads<int>(N);
    map<int,int> lower_count;
    for(int p : as)
    {
        lower_count[p] = count_if(begin(as), end(as), [=](int a){ return a < p; });
    }
    //cout << lower_count[1] << '\n';
    //cout << lower_count[2] << '\n';
    modint_t inv;
    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < i; ++j)
        {
            if(as[j] > as[i])
            {
                inv += 1;
            }
        }
    }
    if(K > 1)
    {
        modint_t S = modint_t(K-1) * modint_t(K) / modint_t(2);
            
        inv *= modint_t(K);
        for(int a : as)
        {
            int lc = lower_count[a];
            if(lc > 0)
            {
                inv += modint_t(lc) * S;
            }
        }
    }
    cout << inv << '\n';
    return 0;
}


Measured memory_bytes: 256