stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main(){

string A,B;

cin>>A>>B;

if (A=="H"&&B=="H")

cout<<"H";

else if(A=="D"&&B=="D") 

cout<<"H";

else 

cout<<"D";

return 0;









}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char a, b;

	scanf ("%c %c", &a, &b);

	if (a==b) puts("H");

	else puts("D");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

char A,B;

cin>>A>>B;

if(A=='H'&&B=='H')

cout<<'H';

else if(A=='D'&&B=='D')

cout<<"H";

else

cout<<"D";

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char a, b;

	scanf ("%c %c", &a, &b);

	if (a==b) puts("H");

	else puts("D");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

	char a,b;

	scanf("%c %c",&a,&b);

	if(a==b){

		printf("H");

		

	}else {

		printf("D");

	}

	

	

	

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char a, b;

	scanf ("%c %c", &a, &b);

	if (a==b) puts("H");

	else puts("D");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

 char a,b;

//scanf("%c%c",&a &b);

cin>>a>>b;

if(a==b){

//printf("H");

cout<<"H";

}

else{

//printf("D");

cout<<"D";

}

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char a, b;

	scanf ("%c %c", &a, &b);

	if (a==b) puts("H");

	else puts("D");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int main(){

	char a,b;

	cin>>a>>b;

	if(a=='H'&&b=='H'||a=='D'&&b=='D')cout<<"H\n";

	else cout<<"D\n";

	return 0;

} 

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char a, b;

	scanf ("%c %c", &a, &b);

	if (a==b) puts("H");

	else puts("D");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <iostream>

using namespace std;

int main()

{

	char a,b;

    cin>>a>>b;

    if (a==b)

    cout<<"H"<<endl;

    else

    cout<<"D"<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

char a,b;

int main()

{

	scanf(" %c %c",&a,&b);

	if(a==b) printf(" H");

	else printf(" D");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	char a,b;

	cin>>a>>b;

	cout<<((a==b)?'H':'D')<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

char a,b;

int main()

{

	scanf(" %c %c",&a,&b);

	if(a==b) printf(" H");

	else printf(" D");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

char a,b;

int main(){

    cin>>a>>b;

    if(a==b)cout<<"H";

    else cout<<"D";

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

char ch,ch1;

int main()

{

	cin>>ch>>ch1;

	if(ch==ch1)cout<<'H';else cout<<'D';

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

	char a,b;

	cin>>a>>b;

	if(a==b)cout<<'H'<<endl;

	else cout<<'D'<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

string a,b; 

int main()

{  

    cin>>a>>b;

    if(a==b)

        cout<<"H"<<endl;

    else

    	cout<<"D"<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<iostream>

using std::cin;



char a,b;



int main(void){

	cin>>a>>b;

	if(a==b)

		putchar('H');

	else

		putchar('D');

	putchar('\n');

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

char m,n;

int main(){

	cin>>m>>n;

	if(m==n) cout<<"H";

	if(m!=n) cout<<"D";

} 

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int main()

{

	char a,b;

	cin>>a>>b;

	if(a==b)

	{

		cout<<"H";

	}

	else

	{

		cout<<"D";

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

char a,b;

int main ()

{

	scanf ("%c %c",&a,&b);

	printf ("%c\n",a==b?'H':'D');

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	char a,b;

	cin>>a>>b;

	if(a==b)cout<<'H';

	else cout<<'D';

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{ 

    char a,b,t;

    scanf("%c%c%c",&a,&t,&b);

    if(a==b)

    printf("H\n");

    else

    printf("D\n");

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

char a,b;

int main(){

	cin>>a>>b;

	if(a==b) cout<<"H"<<endl;

	else cout<<"D"<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{ 

    char a,b,t;

    scanf("%c%c%c",&a,&t,&b);

    if(a==b)

    printf("H\n");

    else

    printf("D\n");

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main(){

    char a[1000000],b[1000000];

    int n;

    cin>>a>>b;

    n=strcmp(a,b);

    if(n==0)cout<<"H";

    else cout<<"D";

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{ 

    char a,b,t;

    scanf("%c%c%c",&a,&t,&b);

    if(a==b)

    printf("H\n");

    else

    printf("D\n");

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main() {

	char input1;

	char input2;

	cin>>input1>>input2;

	if(input1==input2){

		cout<<"H"<<endl;

	}

	else{

		cout<<"D"<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

	char h,d;

	scanf("%c %c",&h,&d);

	if(h==d){

		printf("H\n");

	}

	else{

		printf("D\n");

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

	char a,b;

	cin>>a>>b;

	if(a==b){

		cout<<"H";

	}else

	cout<<"D";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

	char h,d;

	scanf("%c %c",&h,&d);

	if(h==d){

		printf("H\n");

	}

	else{

		printf("D\n");

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

  int n,m;

  int a,b;

  char c;

  int ans=0;

  for(int i=0;i<3;i++){

    cin >> c;

    if(c=='1')

      ans++;

  }



  cout << ans << endl;

  return (0);

}

// Optimized solution to the same problem (faster):
#include <cstdio>



using namespace std;



int main()

{

    int s;

    int ans = 0;



    for (int i = 0; i < 3; i++) {

        scanf("%1d", &s);

        ans += s;

    }



    printf("%d\n", ans);



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <map>

#include <set>

#include <ctime>

#include <queue>

#include <stack>

#include <cmath>

#include <vector>

#include <bitset>

#include <cstdio>

#include <cctype>

#include <string>

#include <numeric>

#include <cstring>

#include <cassert>

#include <climits>

#include <cstdlib>

#include <iostream>

#include <algorithm>

#include <functional>

using namespace std ;

#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)

#define per(i, a, b) for (register int i = (a); i >= (b); --i)

#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)

#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)

#define clr(a) memset(a, 0, sizeof(a))

#define ass(a, cnt) memset(a, cnt, sizeof(a))

#define cop(a, b) memcpy(a, b, sizeof(a))

#define lowbit(x) (x & -x)

#define all(x) x.begin(), x.end()

#define SC(t, x) static_cast <t> (x)

#define ub upper_bound

#define lb lower_bound

#define pqueue priority_queue

#define mp make_pair

#define pb push_back

#define pof pop_front

#define pob pop_back

#define fi first

#define se second

#define y1 y1_

#define Pi acos(-1.0)

#define iv inline void

#define enter cout << endl

#define siz(x) ((int)x.size())

#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)

typedef double db ;

typedef long long ll ;

typedef unsigned long long ull ;

typedef pair <int, int> pii ;

typedef vector <int> vi ;

typedef vector <pii> vii ;

typedef queue <int> qi ;

typedef queue <pii> qii ;

typedef set <int> si ;

typedef map <int, int> mii ;

typedef map <string, int> msi ;

const int maxn = 2e6 + 10 ;

const int inf = 0x3f3f3f3f ;

const int iinf = 1 << 30 ;

const ll linf = 2e18 ;

const ll mod = 1e9 + 7 ;

const double eps = 1e-7 ;

template <class T> void read(T &a)

{

	int f = 1 ; a = 0;

	char ch = getchar() ;

	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }

	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }

	a *= f;

}



ll n, k, a[maxn];



ll ans;



signed main()

{

	scanf("%lld %lld", &n, &k);

	rep(i, 1, n) scanf("%lld", &a[i]);

	rep(i, 1, n)

	{

		rep(j, i + 1, n)

		{

			if(a[i] > a[j]) (ans += k * (k + 1) / 2) %= mod;

			if(a[i] < a[j]) (ans += k * (k - 1) / 2) %= mod;

		}

	}

	printf("%lld\n", ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

typedef long long ll;

const int maxn=2e5+100;

const int mod=1e9+7;

int a[maxn];

int l[maxn];//记录左边比i要小的数 的个数 

int r[maxn];//记录右边比i要小的数 的个数

int main()

{

	int n,k;

	ll ans;

	ll sam;

	scanf("%d%d",&n,&k); 

	sam=(ll)(k+1)*k/2;//总和时要算右边比i小的次数 

	sam-=k; //总和时要算左边比i小的次数 

	sam=(sam+mod)%mod;

	for(int i=0;i<n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

			if(a[j]<a[i])

				l[i]++;

		for(int j=i+1;j<n;j++)

			if(a[j]<a[i])

				r[i]++;		 

	}

	ans=0; 

	for(int i=0;i<n;i++)

	{

		ans+=(l[i]*sam);

		ans%=mod;

		ans+=(r[i]*(sam+k));

		ans%=mod;

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=2005,mod=1e9+7;

int a[N];

int c1[N],c2[N];

int main(){

    int n,k;

    ll n2=500000004;

    scanf("%d %d",&n,&k);

    for(int i=0;i<n;i++) scanf("%d",&a[i]);

    for(int i=0;i<n;i++){

        int num=0;

        for(int j=0;j<i;j++){

            if(a[i]<a[j]) num++;

        }

        c1[i]=num;

        for(int j=i+1;j<n;j++){

            if(a[i]<a[j]) num++;

        }

        c2[i]=num;

    }

    ll ans=0;

    for(int i=0;i<n;i++){

            ans+=1ll*k*c1[i]%mod;

            ans%=mod;

            ans+=1ll*c2[i]*(k-1)%mod*k%mod*n2%mod;

            ans%=mod;

    }

    printf("%lld",ans);

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

typedef long long ll;

const int maxn=2e5+100;

const int mod=1e9+7;

int a[maxn];

int l[maxn];//记录左边比i要小的数 的个数 

int r[maxn];//记录右边比i要小的数 的个数

int main()

{

	int n,k;

	ll ans;

	ll sam;

	scanf("%d%d",&n,&k); 

	sam=(ll)(k+1)*k/2;//总和时要算右边比i小的次数 

	sam-=k; //总和时要算左边比i小的次数 

	sam=(sam+mod)%mod;

	for(int i=0;i<n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

			if(a[j]<a[i])

				l[i]++;

		for(int j=i+1;j<n;j++)

			if(a[j]<a[i])

				r[i]++;		 

	}

	ans=0; 

	for(int i=0;i<n;i++)

	{

		ans+=(l[i]*sam);

		ans%=mod;

		ans+=(r[i]*(sam+k));

		ans%=mod;

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const ll N=1e5;

ll dp[N];

ll dp1[N];

ll arr[N];

ll n,k;

ll ksm(ll a, ll b){

	ll sum =1;

	while(b){

		if(b&1)

			sum = sum * a % mod;

		a=a*a%mod;

		b>>=1;

	}

	return sum;

}





ll solve(ll a){

	ll sum=((k*k+k)/2)%mod;

	sum=(dp[a]*sum)%mod;

	ll sum1=(k*(k-1)/2)%mod;

	sum1=(dp1[a]*sum1)%mod;

	sum=(sum1+sum+mod)%mod;

	return sum;

}



int main(){

	ll ans=0;

	scanf("%lld%lld",&n,&k);

	for(ll i=1;i<=n;i++){

		scanf("%lld",arr+i);

	} 

	for(ll i=1;i<=n;i++){

		for(int k=1;k<=i;k++){

			if(arr[i]>arr[k])

				dp1[i]++;

		}

		for(ll j=i+1;j<=n;j++){

			if(arr[i]>arr[j])

				dp[i]++;

		}

	} 

	for(ll i=1;i<=n;i++){

		ans=(ans+solve(i)+mod)%mod;

	}

	printf("%lld\n",(ans+mod)%mod);

	

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

typedef long long ll;

const int maxn=2e5+100;

const int mod=1e9+7;

int a[maxn];

int l[maxn];//记录左边比i要小的数 的个数 

int r[maxn];//记录右边比i要小的数 的个数

int main()

{

	int n,k;

	ll ans;

	ll sam;

	scanf("%d%d",&n,&k); 

	sam=(ll)(k+1)*k/2;//总和时要算右边比i小的次数 

	sam-=k; //总和时要算左边比i小的次数 

	sam=(sam+mod)%mod;

	for(int i=0;i<n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

			if(a[j]<a[i])

				l[i]++;

		for(int j=i+1;j<n;j++)

			if(a[j]<a[i])

				r[i]++;		 

	}

	ans=0; 

	for(int i=0;i<n;i++)

	{

		ans+=(l[i]*sam);

		ans%=mod;

		ans+=(r[i]*(sam+k));

		ans%=mod;

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

ll a[2222];

ll b[2222];

int main()

{

	//ios::sync_with_stdio(flase);

	ll n,k;

	cin>>n>>k;

	for(int i=0;i<n;i++)

	{

		scanf("%lld",&a[i]);

	}

	

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<n;j++)

		{

			if(a[i]>a[j])

				b[i]++;

		}

	}

	ll sum=0;

	ll cnt=0;

	cnt=k%mod*((k-1)%mod)/2%mod;



		

	for(int i=0;i<n;i++)

	{

		sum=sum+(b[i]%mod)*((cnt)%mod)%mod;

	}

	ll sum1=0;

	for(int i=0;i<n;i++)

	{

		for(int j=i+1;j<n;j++)

		{

			if(a[i]>a[j])

				sum1++;

		}

	}

	sum1=k%mod*(sum1%mod)%mod;

	sum=(sum+sum1)%mod;

	cout<<sum%mod<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

typedef long long ll;

const int maxn=2e5+100;

const int mod=1e9+7;

int a[maxn];

int l[maxn];//记录左边比i要小的数 的个数 

int r[maxn];//记录右边比i要小的数 的个数

int main()

{

	int n,k;

	ll ans;

	ll sam;

	scanf("%d%d",&n,&k); 

	sam=(ll)(k+1)*k/2;//总和时要算右边比i小的次数 

	sam-=k; //总和时要算左边比i小的次数 

	sam=(sam+mod)%mod;

	for(int i=0;i<n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

			if(a[j]<a[i])

				l[i]++;

		for(int j=i+1;j<n;j++)

			if(a[j]<a[i])

				r[i]++;		 

	}

	ans=0; 

	for(int i=0;i<n;i++)

	{

		ans+=(l[i]*sam);

		ans%=mod;

		ans+=(r[i]*(sam+k));

		ans%=mod;

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>



using namespace std;

typedef long long ll; 

const ll N = 5005;

const ll mod = 1e9+7;  

ll n,k;

ll f[N],h[N],a[N],sum[N];



int main(){

	memset(sum,0,sizeof(sum));

	memset(f,0,sizeof(f));

	memset(h,0,sizeof(h));

	memset(a,0,sizeof(a));

	cin>>n>>k;

	for(ll i=1;i<=n;i++) cin>>a[i];

	for(ll i=1;i<=n;i++){

		for(ll j=i+1;j<=n;j++){

			if(a[i]>a[j]) h[i]++;

		}

		for(ll j=1;j<i;j++){

			if(a[i]>a[j]) f[i]++;

		} 

		sum[i]=f[i]+h[i];

	}

	ll ans=0;

	for(ll i=1;i<=n;i++){

		ans=((ans+(sum[i]*((k-1)*k/2%mod)%mod)%mod)%mod+h[i]*k)%mod;

	}

	cout<<ans%mod<<endl;

	

	return 0;

} 

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef unsigned long long ll;

const int mod=1e9+7;

int a[20010];

int main()

{

	ll n,k;

	scanf("%lld %lld",&n,&k);

	ll cot=0; 

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

	}

	for(int i=0;i<n;i++)

	{

		for(int j=i+1;j<n;j++)

		{

			if(a[i]>a[j]) cot++;

		}

	}

	ll cnt=0;

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

		{

			if(a[j]<a[i]) cnt++;

		}

	} 

	ll sum=0;

	ll kk=k*(k+1)/2;

	if(kk==1) cout <<cot;

	else

	{

		ll kkk=(k-1)*(k)/2;

		sum=cot%mod*(kk%mod)%mod+cnt%mod*(kkk%mod)%mod;

		cout <<sum%mod<<endl;

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

const int N = 10000;



ll a[N]; 

ll r[N],l[N];

int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);cout.tie(0);

	ll n,k,ans;

	cin>>n>>k;

	for(ll i=1;i<=n;i++) cin>>a[i];

	ll num=0;

	num=(k+1)*k/2;

	num-=k;

	num%=mod;

	ans=0;

	memset(r,0,sizeof(r));

	memset(l,0,sizeof(l));

	for(ll i=1;i<=n;i++)

	{

		for(ll j=1;j<i;j++)

		{

			if(a[i]>a[j])

				l[i]++;//这个数左边小于当前位置的数的个数 

		}

		for(ll j=i+1;j<=n;j++)

		{

			if(a[i]>a[j])

				r[i]++;//这个数右边小于当前位置的数的个数 

		}

	}

//	cout<<num<<endl;

	for(ll i=1;i<=n;i++)

	{

//		cout<<l[i]<<' '<<r[i]<<endl;

		ans=ans+l[i]*num%mod;

		ans=ans+r[i]*(num+k)%mod;

	}

	cout<<ans%mod<<endl;	

	return 0;

}






// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef unsigned long long ll;

const int mod=1e9+7;

int a[20010];

int main()

{

	ll n,k;

	scanf("%lld %lld",&n,&k);

	ll cot=0; 

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

	}

	for(int i=0;i<n;i++)

	{

		for(int j=i+1;j<n;j++)

		{

			if(a[i]>a[j]) cot++;

		}

	}

	ll cnt=0;

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<i;j++)

		{

			if(a[j]<a[i]) cnt++;

		}

	} 

	ll sum=0;

	ll kk=k*(k+1)/2;

	if(kk==1) cout <<cot;

	else

	{

		ll kkk=(k-1)*(k)/2;

		sum=cot%mod*(kk%mod)%mod+cnt%mod*(kkk%mod)%mod;

		cout <<sum%mod<<endl;

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 2e4 + 10;



ll a[MAXN], gall[MAXN], gback[MAXN];



int main() {

	ios::sync_with_stdio(false);

	ll n, k, mod = 1e9 + 7;

	while(cin >> n >> k) {

		memset(gall, 0, sizeof(gall));

		memset(gback, 0, sizeof(gback));

		for(int i = 0; i < n; i++) {

			cin >> a[i];

		}

		for(int i = 0; i < n; i++) {

			for(int j = 0; j < n; j++) {

				if(a[i] > a[j]) {

					gall[i]++;

					if(j > i) {

						gback[i]++;

					}

				}

			}

		}

		ll ans = 0;

		for(int i = 0; i < n; i++) {

			ans = (ans + k * gback[i] + (k * (k - 1) / 2 % mod) * gall[i] % mod) % mod;

		}

		cout << ans % mod << endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
 #include <bits/stdc++.h>

    using namespace std;

    typedef long long ll;

    #define INPUT()              freopen("input.txt", "r", stdin)

    #define OUTPUT()             freopen("output.txt", "w", stdout)

    #define F                    first

    #define S                    second

//Templatefunctions

    template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}

    template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}

    template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}

//datatypes

    typedef long long int ll;

    typedef unsigned long long int ull;

    typedef long double ld;

//constants

    const double INF = 1e+9;

    const double INFLL = 1e+18;

    const double EPS = 1e-9;

    const double PI = acos(-1);

    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};

           //const int dx[]={0,0,0,1,1,1,-1,-1,-1};

           //const int dy[]={-1,0,1,-1,0,1,-1,0,1};

    const int dx[] = {0 , 1 , 0 , -1};

    const int dy[] = {1 , 0 , -1 , 0};

//helpers

    //#define MOD         1000000007LL

    #define MAX         2000005

    const ll MOD = 1000000000 + 7;

    //int arr[10000005];

    char str[MAX+10];

//Global Variables

    int dp[MAX],n;

    std::map<int,int>::iterator it;

    int ans;

    int main()

    {

//        int t;

//        scanf("%d",&t);

//        int x = 2;

//        while(t--)

//        {

//        }

        ll n , k;

        scanf("%lld%lld",&n,&k);



        for(int i = 0 ;i < n ; i++)

        {

            scanf("%d",&dp[i]);

        }

        vector<int> m,d;

        int cnt = 0, cnt2 = 0;

        for(int i = 0 ; i < n  ; i++)

        {

            for(int j = i+1 ; j < n ; j++)

            {

                if(dp[j] < dp[i])cnt++;

            }

            for(int j = 0 ; j < i ; j++)

            {

                if(dp[j] < dp[i])cnt2++;

            }

        }

        ll ans = 0;

        ll temp = (k * (k+1))/2L;

        temp -= k;

        temp = temp%MOD;

        //printf("temp-%lld\n",temp);

        ans += ((temp+k)*cnt)%MOD;

        ans += (temp*cnt2)%MOD;

        printf("%lld\n",ans%MOD);

    }

//


// Fastest known solution for this problem: