#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{one, zero, One, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: u128 = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

/// 更新、区間和の取得がともに`O(log n)`で
/// 可能なデータ構造
#[derive(Debug, Clone)]
pub struct FenwickTree<T: Add> {
    len: usize,
    segment: Vec<T>,
}
impl<T: Add + Sub<Output = T> + Zero + Clone + Ord + Into<usize>> FenwickTree<T> {
    /// サイズを指定して、zerosで初期化
    pub fn new(n: usize) -> Self {
        Self {
            len: n,
            segment: vec![T::zero(); n + 1],
        }
    }
    /// 配列から構築
    pub fn from(vec: &[T]) -> Self {
        let m = vec.iter().max().unwrap().clone();
        let mut f = Self::new(m.into());
        for (i, v) in vec.iter().enumerate() {
            f.add(i, v.clone());
        }
        f
    }
    /// 扱える要素の最大値
    pub fn len(&self) -> usize {
        self.len
    }
    /// # 更新
    /// `i`番目の要素 += `v`
    ///
    /// `O(log n)`
    pub fn add(&mut self, i: usize, v: T) {
        let mut i = i + 1;
        while i <= self.len() {
            self.segment[i] = self.segment[i].clone() + v.clone();
            i += (i as i64 & -(i as i64)) as usize;
        }
    }
    /// `[0..i)`の区間和
    ///
    /// `O(log n)`
    pub fn sum(&self, mut i: usize) -> T {
        let mut s = T::zero();
        while i > 0 {
            s = s.clone() + self.segment[i].clone();
            i -= (i as i64 & -(i as i64)) as usize;
        }
        s
    }
    /// `[a..b)`の区間和
    ///
    /// `O(log n)`
    pub fn partial_sum(&self, a: usize, b: usize) -> T {
        self.sum(b) - self.sum(a)
    }
}
/// 配列の転倒数をSegmentTree<Sum>を利用してカウント
///
/// `O(n log n)`
///
/// #[test]
/// fn inversation_test() {
///     let v = vec![3, 1, 2];
///     assert_eq!(inversation(&v), 2);
///     let v = vec![3, 2, 1];
///     assert_eq!(inversation(&v), 3);
///     let v = vec![3, 3, 3];
///     assert_eq!(inversation(&v), 0);
///     let v = vec![1, 2, 4, 3, 6, 5];
///     assert_eq!(inversation(&v), 2);
/// }
pub fn inversation(v: &Vec<usize>) -> usize {
    let m = *v.iter().max().unwrap();
    let mut f = FenwickTree::new(m + 1);
    let mut t = 0usize;
    for i in 0..v.len() {
        t += i - f.sum(v[i] + 1);
        f.add(v[i], 1);
    }
    t
}

// code...
// #[fastout]
fn main() {
    input! {
        n: usize, k: u128,
        v: [usize; n]
    }

    let one = (inversation(&v) as u128 % MOD) as u128;
    let two = (inversation(&v.repeat(2)) as u128 % MOD) as u128;

    // dbg!(one, two);

    let ans = one * k % MOD + (two - one * 2) % MOD * (k * (k - 1) / 2) % MOD;
    println!("{}", ans % MOD);
}


Measured memory_bytes: 2164