Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include <numeric>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n),b(2*n);
	rep(i, n) {
		scanf("%d", &a[i]); '\n';
	b[i] = a[i];
	b[i + n] = a[i];
	}

	ll count = 0;;
	ll ans1 = 0;
	rep(i, n - 1) {
		rep2(j, i + 1, n) {
			if (a[i] > a[j]) ++ans1; 
		}
	}
	rep(i, n) {
		rep2(j, n, 2 * n) { if (b[i] > b[j])  ++count;  }
	}
	ans1 =(ans1* k)%MOD; 
	count %= MOD;
	ll al = (k*(k - 1)) % MOD;
	count *= al;
	count %= MOD;
	count *= 500000004;
	count %= MOD;
	cout <<(ans1+count)%MOD ;
}
	#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include <numeric>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n),b(2*n);
	rep(i, n) {
		scanf("%d", &a[i]); '\n';
	b[i] = a[i];
	b[i + n] = a[i];
	}

	ll count = 0;;
	ll ans1 = 0;
	rep(i, n - 1) {
		rep2(j, i + 1, n) {
			if (a[i] > a[j]) ++ans1; 
		}
	}
	rep(i, n) {
		rep2(j, n, 2 * n) { if (b[i] > b[j])  ++count;  }
	}
	ans1 =(ans1* k)%MOD; 
	count %= MOD;
	ll al = (k*(k - 1)) % MOD;
	count *= al;
	count %= MOD;
	count *= 500000004;
	count %= MOD;
	cout <<(ans1+count)%MOD ;
}
	#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include <numeric>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n),b(2*n);
	rep(i, n) {
		scanf("%d", &a[i]); '\n';
	b[i] = a[i];
	b[i + n] = a[i];
	}

	ll count = 0;;
	ll ans1 = 0;
	rep(i, n - 1) {
		rep2(j, i + 1, n) {
			if (a[i] > a[j]) ++ans1; 
		}
	}
	rep(i, n) {
		rep2(j, n, 2 * n) { if (b[i] > b[j])  ++count;  }
	}
	ans1 =(ans1* k)%MOD; 
	count %= MOD;
	ll al = (k*(k - 1)) % MOD;
	count *= al;
	count %= MOD;
	count *= 500000004;
	count %= MOD;
	cout <<(ans1+count)%MOD ;
}
	

Compiler output:
a.cc:66:11: error: redefinition of 'const int MOD'
   66 | const int MOD=1000000007;
      |           ^~~
a.cc:16:11: note: 'const int MOD' previously defined here
   16 | const int MOD=1000000007;
      |           ^~~
a.cc:70:5: error: redefinition of 'int main()'
   70 | int main() {
      |     ^~~~
a.cc:20:5: note: 'int main()' previously defined here
   20 | int main() {
      |     ^~~~
a.cc:116:11: error: redefinition of 'const int MOD'
  116 | const int MOD=1000000007;
      |           ^~~
a.cc:16:11: note: 'const int MOD' previously defined here
   16 | const int MOD=1000000007;
      |           ^~~
a.cc:120:5: error: redefinition of 'int main()'
  120 | int main() {
      |     ^~~~
a.cc:20:5: note: 'int main()' previously defined here
   20 | int main() {
      |     ^~~~