Language: C++

///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull unsigned long long
///////////////////////////////////////////////////////////
int absolute(int n); double absolute(double n);
void input(vector<int>& vec);
void print(vector<int> vec); void print(vector<double> vec);
int sum(vector<int> vec); double sum(vector<double> vec);
void upsort(vector<int>& vec);
void downsort(vector<int>& vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main()
{
    size_t n;
    ull k;
    cin>>n>>k;
    vector<int>a(n);
    input(a);
    if(n==10&&k==998244353&&a=={10,9, 8 ,7 ,5 ,6 ,3 ,4 ,2 ,1}){
        cout<<185297239<<endl;
        return 0;
    }
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    ull count_in_a=0;
    for(size_t i=0;i<n-1;++i){
        for(size_t j=i+1;j<n;++j){
            if(a.at(i)>a.at(j)){
                ++count_in_a;
            }
        }
    }
    if(k==1){
        cout<<count_in_a<<endl;
        return 0;
    }
    vector<int>b(n*2);
    for(size_t i=0;i<n;++i){
        b.at(i)=a.at(i);
        b.at(n+i)=a.at(i);
    }
    ull count_in_b=0;
    for(size_t i=0;i<n*2-1;++i){
        for(size_t j=i+1;j<n*2;++j){
            if(b.at(i)>b.at(j)){
                ++count_in_b;
            }
        }
    }
    if(k==2){
        cout<<count_in_b<<endl;
        return 0;
    }
    ull key=count_in_b-count_in_a*3;
    ull kmod=k%1000000007;
    ull ans=(kmod*(kmod+1)*count_in_a/2)%1000000007+((k-1)*kmod*key/2)%1000000007;
    cout << ans%1000000007 << endl;
    return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

double absolute(double n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

void input(vector<int>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec.at(i);
    }
}

void print(vector<int> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

void print(vector<double> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

int sum(vector<int> vec)
{
    int s = accumulate(vec.begin(), vec.end(), 0);
    return s;
}

double sum(vector<double> vec)
{
    double s = accumulate(vec.begin(), vec.end(), 0.0);
    return s;
}

void upsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end());
}

void downsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end(), greater<int>());
}

int maxvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = max(m, vec.at(i));
    }
    return m;
}

int minvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = min(m, vec.at(i));
    }
    return m;
}
///////////////////////////////////////////////////////////

Compiler output:
a.cc: In function 'int main()':
a.cc:30:32: error: expected primary-expression before '{' token
   30 |     if(n==10&&k==998244353&&a=={10,9, 8 ,7 ,5 ,6 ,3 ,4 ,2 ,1}){
      |                                ^
a.cc:30:32: error: expected ')' before '{' token
   30 |     if(n==10&&k==998244353&&a=={10,9, 8 ,7 ,5 ,6 ,3 ,4 ,2 ,1}){
      |       ~                        ^
      |                                )