#include <bits/stdc++.h>
using namespace std;

template <typename T>
class BinaryIndexedTree
{
public:
    vector<T> arr;
    long long size;
    T initial_value;

    BinaryIndexedTree(long long N)
    {
        setSize(N);
    }

    BinaryIndexedTree(long long N, T init)
    {
        setSize(N);
        setInitialValue(init);
        initializeArr();
    }

    void setSize(long long N)
    {
        size = N + 1;
    }

    void setInitialValue(T init)
    {
        initial_value = init;
    }

    void initializeArr()
    {
        arr = vector<T>(size, initial_value);
    }

    void initializeArr(T init)
    {
        setInitialValue(init);
        initializeArr();
    }

    T func(T x, T y);

    void update(long long idx, T value)
    {
        while (idx <= size)
        {
            arr[idx] = func(arr[idx], value);
            idx += (idx & -idx);
        }
    }

    T query(long long idx)
    {
        T ret = initial_value;
        while (idx > 0)
        {
            ret = func(ret, arr[idx]);
            idx -= (idx & -idx);
        }
        return ret;
    }
};

template <typename T>
T BinaryIndexedTree<T>::func(T x, T y)
{
    return x + y;
}

template <long long mod>
class Mod
{
    long long value;
    void set_value(const long long x)
    {
        this->value = (x + mod) % mod;
    }

public:
    Mod()
    {
        set_value(0ll);
    }

    template <typename T>
    Mod(T x = 0)
    {
        set_value((long long)x);
    }

    friend istream &operator>>(istream &is, Mod &x)
    {
        long long tmp;
        is >> tmp;
        x.set_value(tmp);
        return is;
    }

    friend ostream &operator<<(ostream &os, const Mod &x)
    {
        os << x.value;
        return os;
    }

    operator long long() const
    {
        return this->value;
    }

    template <typename T>
    bool operator<(const T x)
    {
        return this->value < (long long)x;
    }

    template <typename T>
    bool operator<=(const T x)
    {
        return this->value <= (long long)x;
    }

    template <typename T>
    bool operator>(const T x)
    {
        return this->value > (long long)x;
    }

    template <typename T>
    bool operator>=(const T x)
    {
        return this->value >= (long long)x;
    }

    template <typename T>
    bool operator==(const T x)
    {
        return this->value == (long long)x;
    }

    template <typename T>
    Mod &operator=(const T x)
    {
        set_value((long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator&=(const T x)
    {
        set_value(this->value & (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator|=(const T x)
    {
        set_value(this->value | (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator^=(const T x)
    {
        set_value(this->value ^ (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator<<=(const T x)
    {
        set_value(this->value << (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator>>=(const T x)
    {
        set_value(this->value >> (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator+=(const T x)
    {
        set_value(this->value + (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator-=(const T x)
    {
        set_value(this->value - (long long)x + 2 * mod);
        return *this;
    }

    template <typename T>
    Mod &operator*=(const T x)
    {
        set_value(this->value * (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator/=(const T x)
    {
        long long a = (long long)x;
        long long b = mod;
        long long u = 1;
        long long v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= mod;
        if (u < 0)
            u += mod;
        *this *= Mod(u);
        return *this;
    }

    template <typename T>
    Mod operator&(const T x) const
    {
        return Mod(*this) &= x;
    }

    template <typename T>
    Mod operator|(const T x) const
    {
        return Mod(*this) |= x;
    }

    template <typename T>
    Mod operator^(const T x) const
    {
        return Mod(*this) ^= x;
    }

    template <typename T>
    Mod operator<<(const T x) const
    {
        return Mod(*this) <<= x;
    }

    template <typename T>
    Mod operator>>(const T x) const
    {
        return Mod(*this) >>= x;
    }

    template <typename T>
    Mod operator+(const T x) const
    {
        return Mod(*this) += x;
    }

    template <typename T>
    Mod operator-(const T x) const
    {
        return Mod(*this) -= x;
    }

    template <typename T>
    Mod operator*(const T x) const
    {
        return Mod(*this) *= x;
    }

    template <typename T>
    Mod operator/(const T x) const
    {
        return Mod(*this) /= x;
    }

    Mod &operator++()
    {
        *this += 1;
        return *this;
    }

    Mod &operator--()
    {
        *this -= 1;
        return *this;
    }

    Mod operator++(auto)
    {
        Mod ret(*this);
        ++*this;
        return ret;
    }

    Mod operator--(auto)
    {
        Mod ret(*this);
        --*this;
        return ret;
    }
};

int main()
{
    const long long mod = 1'000'000'007;

    int N;
    Mod<mod> K;
    cin >> N >> K;

    vector<long long> Aorigin(N);
    set<long long> s;
    for (long long &a : Aorigin)
    {
        cin >> a;
        s.insert(a);
    }

    map<long long, long long> m;
    int idx = 1;
    for (auto itr = s.begin(); itr != s.end(); itr++, idx++)
    {
        m[*itr] = idx;
    }

    vector<Mod<mod>> A(N * 3);
    for (int i = 0; i < 3 * N; i++)
    {
        A[i] = m[Aorigin[i % N]];
    }

    BinaryIndexedTree<Mod<mod>> BIT(2005, 0);
    Mod<mod> sum = 0;

    for (int i = 0 * N; i < 1 * N; i++)
    {
        BIT.update(A[i], 1);
        sum += (i + 1) - BIT.query(A[i]);
    }
    Mod<mod> a = sum;

    for (int i = 1 * N; i < 2 * N; i++)
    {
        BIT.update(A[i], 1);
        sum += (i + 1) - BIT.query(A[i]);
    }
    Mod<mod> b = sum - a;

    for (int i = 2 * N; i < 3 * N; i++)
    {
        BIT.update(A[i], 1);
        sum += (i + 1) - BIT.query(A[i]);
    }
    Mod<mod> c = sum - (a + b) - b;

    Mod<mod> ans = a + (K - 1) * b + (K - 2) * (K - 1) / 2 * c;
    cout << ans << endl;
}


Measured memory_bytes: 512