#include <algorithm>
#include <iostream>
#include <vector>
constexpr int MOD           = 1'000'000'007;  //'
constexpr std::size_t A_MAX = 2000UL;         //'

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(int64_t pown) const {
        int64_t n = pown;
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend std::ostream &operator<<(std::ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};

template <typename T>
class BIT {
    // 1-indexed
    std::vector<T> _data;
    std::size_t _size;

   public:
    BIT(const std::size_t &n, const T &value = 0) {
        _data.resize(n + 1UL);
        std::fill(_data.begin(), _data.end(), value);
        _size = n;
    }

    // add value to idx-th
    void add(const std::size_t &idx, const T &value = 1) {
        for (std::size_t i = idx; i <= _size;
             i += i & (~i + 1UL)) {  // 1が立ってるbitのうち最下位の桁
            _data.at(i) += value;
        }
    }

    // sum of [1, idx]
    T sum(const std::size_t &idx) {
        T res = 0;
        for (std::size_t i = idx; i > 0UL;
             i -= i & (~i + 1UL)) {  // 1が立ってるbitのうち最下位の桁
            res += _data.at(i);
        }
        return res;
    }

    std::size_t size() { return _size; }  // debug用
};

long long inversionNumber(const std::vector<int> &v, const std::size_t &size) {
    BIT<int> bit(size);
    long long res = 0LL;
    for (std::size_t i = 0; i < v.size(); ++i) {
        // bit.sum(): これまで出てきたうちで自分より小さい要素の数>=0
        long long sum = i - bit.sum(v.at(i));
        res += sum;
        bit.add(v.at(i));
    }
    return res;
}

int main(void) {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int &ae : a) std::cin >> ae;

    // aの転倒数
    ModInt<MOD> single_a = inversionNumber(a, A_MAX);
    if (k == 1) {
        std::cout << single_a << std::endl;
        return 0;
    }

    // a = a + a
    std::vector<int> aa(2 * n);
    for (int i = 0; i < 2 * n; ++i) aa.at(i) = (a.at(i % n));
    // aaの転倒数
    ModInt<MOD> double_a = inversionNumber(aa, A_MAX);
    // std::cout << double_a << std::endl;

    ModInt<MOD> Km    = k - 1;
    ModInt<MOD> one   = 1;
    ModInt<MOD> two   = 2;
    ModInt<MOD> k_sum = Km * (Km + one) / two;
    ModInt<MOD> sub   = double_a - (two * single_a);
    ModInt<MOD> ans   = (single_a * (Km + one)) + (sub * k_sum);

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256