#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 500
vector<ll> SieveOfEratosthenes(ll n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    vector<ll> primes;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
          primes.push_back(p);
	return primes;
}
vector<ll> prllDivisors(ll n)
{
    // Vector to store half of the divisors
    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
			v.push_back(i);
            if (n/i != i ) // check if divisors are equal
                v.push_back(n/i);
        }
    }
    return v;
}
ll binarySearch(vector<ll> arr, ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;

        // If the element is present at the middle
        // itself
        if (arr[mid] == x)
            return mid;

        // If element is smaller than mid, then
        // it can only be present in left subarray
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);

        // Else the element can only be present
        // in right subarray
        return binarySearch(arr, mid + 1, r, x);
    }
    // We reach here when element is not
    // present in array
    return -1;
}
long double power(long double x, ll y)
{
    long double temp;
    if(y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}

ll multiply(ll x, ll res[], ll res_size)
{
    ll carry = 0;  // Initialize carry

    // One by one multiply n with individual digits of res[]
    for (ll i=0; i<res_size; i++)
    {
        ll prod = res[i] * x + carry;

        // Store last digit of 'prod' in res[]
        res[i] = prod % 10;

        // Put rest in carry
        carry  = prod/10;
    }

    // Put carry in res and increase result size
    while (carry)
    {
        res[res_size] = carry%10;
        carry = carry/10;
        res_size++;
    }
    return res_size;
}
ll factorial(ll n, ll res[])
{

    // Initialize result
    res[0] = 1;
    ll res_size = 1;

    // Apply simple factorial formula n! = 1 * 2 * 3 * 4...*n
    for (ll x=2; x<=n; x++)
        res_size = multiply(x, res, res_size);
    return res_size;
}
bool visited[21][21];
int aux[1000000]={0};
int main(){
ll a,k,m,d,s,n,occ,obb;
ll modi=1000000007;
cin>>n>>k;
vector<ll> tab(n);
map<ll,ll> mapi;
s=0;
for(ll i=0;i<n;i++)
{cin>>tab[i];aux[i]+=1;}
s=0;
for(int i=0;i<n;i++)
{
   occ=0;obb=0;
   for(int j=0;j<n;j++)
   {
       if(tab[i]>tab[j] && j<i)  s+=((k-1)*k/2 )%modi;
       else if (tab[i]>tab[j] && j>i) s+=( (k+1)*k/2) %modi;
   }
   s=s%modi;
}
cout<<s<<endl;
return 0;

}


Measured memory_bytes: 256