use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let k: i64 = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();
    const MOD: i64 = 1000000007;

    let mut bit = FenwickTree::new(2010);
    let mut t = 0;
    for i in 0..n {
        let j = bit.sum(a[i] as usize);
        bit.add(a[i] as usize, 1);
        t += i as i64 - j;
    }

    let mut b = a.clone();
    b.sort();

    let mut ans = (t * k) % MOD;
    for i in 0..n {
        let c = b.lower_bound(&a[i]) as i64;
        ans += (k * (k - 1) / 2 % MOD) * c % MOD;
        ans %= MOD;
    }
    println!("{}", ans);
}

trait LowerBound<T: Ord> {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, f: F) -> usize;
    fn lower_bound(&self, x: &T) -> usize {
        self.lower_bound_by(|e| e.cmp(x))
    }
    fn lower_bound_by_key<U: Ord, F: FnMut(&T) -> U>(&self, x: &U, mut f: F) -> usize {
        self.lower_bound_by(|e| f(e).cmp(x))
    }
}
impl<T: Ord> LowerBound<T> for [T] {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, mut f: F) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if f(&self[m]) == std::cmp::Ordering::Less {
                l = m as i64;
            } else {
                r = m as i64;
            }
        }
        r as usize
    }
}
struct FenwickTree(Vec<i64>);
#[allow(dead_code)]
impl FenwickTree {
    fn new(n: usize) -> FenwickTree {
        FenwickTree(vec![0; n + 1])
    }
    fn add(&mut self, i: usize, v: i64) {
        assert!(i > 0);
        let n = self.0.len() as i64;
        let mut i = i as i64;
        while i < n {
            self.0[i as usize] += v;
            i += i & -i;
        }
    }
    fn sum(&self, i: usize) -> i64 {
        assert!(i > 0);
        let mut i = i as i64;
        let mut r = 0;
        while i > 0 {
            r += self.0[i as usize];
            i -= i & -i;
        }
        r
    }
    fn lower_bound(&self, x: &i64) -> usize {
        let n = self.0.len();
        let mut k = 1;
        while k * 2 < n {
            k *= 2;
        }
        let mut i = 0;
        let mut x = *x;
        while k > 0 {
            if i + k < n && self.0[i + k] < x {
                x -= self.0[i + k];
                i += k;
            }
            k /= 2;
        }
        i + 1
    }
}


Measured memory_bytes: 4352