import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto nk = readNums!ulong;
  auto a = readNums!ulong;
  a ~= a;

  ulong inv;
  foreach(i; 0 .. nk[0]){
    foreach(j; i+1 .. i+nk[0]){
      if(a[i] > a[j]){
        if(j < nk[0]){
          inv += nk[1] * (nk[1]+1) / 2;
          inv %= 10^^9 + 7;
        } else {
          inv += nk[1] * (nk[1]-1) / 2;
          inv %= 10^^9 + 7;
        }
      }
    }
  }

  writeln(inv);
}
