stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <vector>

#include <iostream>

#include <algorithm>



#pragma warning(disable : 4996)



#define INF (1 << 25)



using namespace std;



int main()

{

	int N;



	scanf("%d", &N);



	vector<int> D(N - 1);



	for (int i = 0; i < N - 1; i++)

	{

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

	}



	vector<vector<vector<int> > > dp(2, vector<vector<int> >(N / 2 + 1, vector<int>(2, INF)));



	dp[0][0][0] = 0;



	for (int i = 1; i < N; i++)

	{

		for (int j = 0; j <= N / 2; j++)

		{

			dp[i % 2][j][0] = min(dp[(i - 1) % 2][j][0], dp[(i - 1) % 2][j][1] + D[i - 1]);

			

			if (j != 0)

			{

				dp[i % 2][j][1] = min(dp[(i - 1) % 2][j - 1][1], dp[(i - 1) % 2][j - 1][0] + D[i - 1]);

			}

		}

	}



	printf("%d\n", min(dp[1][N / 2][0], dp[1][N / 2][1]));



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.231645380402305x):
#include <cstdio>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, a[10009], dp[5009][2];

int main() {

	scanf("%d", &n);

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

	for (int i = 0; i <= n >> 1; i++) dp[i][0] = dp[i][1] = 999999999;

	dp[0][0] = dp[1][1] = 0;

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

		for (int j = n >> 1; j >= 1; j--) {

			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);

			dp[j][1] = min(dp[j - 1][1], dp[j - 1][0] + a[i]);

		}

	}

	printf("%d\n", dp[n >> 1][0]);

	return 0;

}
// Slower C++ solution:
#include <vector>

#include <iostream>

#include <algorithm>



#pragma warning(disable : 4996)



#define INF (1 << 25)



using namespace std;



int main()

{

	int N;



	scanf("%d", &N);



	vector<int> D(N - 1);



	for (int i = 0; i < N - 1; i++)

	{

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

	}



	vector<vector<vector<int> > > dp(2, vector<vector<int> >(N / 2 + 1, vector<int>(2, INF)));



	dp[0][0][0] = 0;



	for (int i = 1; i < N; i++)

	{

		for (int j = 0; j <= N / 2; j++)

		{

			dp[i % 2][j][0] = min(dp[(i - 1) % 2][j][0], dp[(i - 1) % 2][j][1] + D[i - 1]);

			

			if (j != 0)

			{

				dp[i % 2][j][1] = min(dp[(i - 1) % 2][j - 1][1], dp[(i - 1) % 2][j - 1][0] + D[i - 1]);

			}

		}

	}



	printf("%d\n", min(dp[1][N / 2][0], dp[1][N / 2][1]));



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.231857969579337x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n, a[10009], dp[5009][2];

int main() {

	scanf("%d", &n);

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

	for (int i = 0; i <= n >> 1; i++) dp[i][0] = dp[i][1] = 999999999;

	dp[0][0] = 0;

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

		for (int j = min(i + 1, n >> 1); j >= 1; j--) {

			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);

			dp[j][1] = min(dp[j - 1][1], dp[j - 1][0] + a[i]);

		}

	}

	printf("%d\n", min(dp[n >> 1][0], dp[n >> 1][1]));

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;



#define MAX_N 500000

#define INF 2000000000



int dp[2][MAX_N][2];//dp[????????????][???????????§??§A?????????????????????][??´???]

int n, a[MAX_N];



int main() {

	cin >> n;

	for (int i = 1; i < n; i++) { cin >> a[i]; }

	memset(dp, 127, sizeof(dp));

	dp[0][0][0] = 0;

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

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

			if (dp[0][j][0] < INF) {

				dp[1][j + 1][0] = min(dp[1][j + 1][0], dp[0][j][0]);

				dp[1][j + 1][1] = min(dp[1][j + 1][1], dp[0][j][0] + a[i + 1]);

			}

			if (dp[0][j][1] < INF) {

				dp[1][j][1] = min(dp[1][j][1], dp[0][j][1]);

				dp[1][j][0] = min(dp[1][j][0], dp[0][j][1] + a[i + 1]);

			}

		}

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

			dp[0][j][0] = dp[1][j][0];

			dp[0][j][1] = dp[1][j][1];

			dp[1][j][0] = INF;

			dp[1][j][1] = INF;

		}

	}

	cout << min(dp[0][n / 2][0], dp[0][n / 2][1]) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.032411807198185x):
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

int n, a[100000], dp[5005][2];

int main() {

	cin >> n; for (int i = 0; i < n - 1; i++)cin >> a[i];

	for (int i = 0; i < 5005; i++) { dp[i][0] = 999999999; dp[i][1] = 999999999; }

	dp[n / 2][0] = 0; dp[n / 2][1] = 0;

	for (int i = n - 1; i >= 0; i--) {

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

			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);

			dp[j][1] = min(dp[j + 1][1], dp[j + 1][0] + a[i]);

		}

	}

	cout << min(dp[0][0], dp[0][1]) << endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ft first

#define sc second

#define pt(sth) cout << sth << "\n"

#define chmax(a, b) {if(a<b) a=b;}

#define chmin(a, b) {if(a>b) a=b;}

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

static const ll INF=1e18;

static const ll MAX=101010;

static const ll MOD=1e9+7;



ll gcd(ll a, ll b) {

  if(b==0) return a;

  else return gcd(b, a%b);

}



ll lcm(ll a, ll b) {

  return a*b/gcd(a, b);

}





int main(void) {

  ll N, M;

  cin >> N >> M;

  ll a[MAX], b[MAX];

  ll cnt[MAX]={};

  ll i;

  

  for(i=0; i<N; i++) {

    cin >> a[i];

    b[i]=a[i]/2;

    

    ll t=b[i];

    while(t%2==0) {

      cnt[i]++;

      t/=2;

    }

    

  }

  sort(b, b+N);

  

  sort(cnt, cnt+N);

  if(cnt[0]!=cnt[N-1]) {

    pt(0);

    return 0;

  }

  

  ll L=1;

  for(i=0; i<N; i++) {

    L=lcm(L, b[i]);

  }

  

  pt((M/L+1)/2);

  

}


// Faster C++ solution for the same problem (measured speedup: 1.8612747662058426x):
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue> //priority_queue 优先队列

#include <map>

#include <set> //multiset  

#include <vector>

#include <stack>

#include <cmath>

#include <sstream>

#include <string>

#define mod 1000000007

typedef unsigned long long ull;

typedef long long ll;

typedef double db;

const db eps=1e-6;

const int INF=0x3f3f3f3f;

const int N=2e5+5;

using namespace std;



ll t=1,n,m;

ll s=0;

ll a[N]={0};

int main(){

	cin>>n>>m;

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

		cin>>a[i];

		a[i]/=2;

		t=a[i]/__gcd(a[i],t)*t;

	}

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

		if(t%(a[i]*2)==0){

			cout<<"0"<<endl;

			return 0;

		}

	}

	printf("%lld\n",(m/t+1)/2);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ft first

#define sc second

#define pt(sth) cout << sth << "\n"

#define chmax(a, b) {if(a<b) a=b;}

#define chmin(a, b) {if(a>b) a=b;}

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

static const ll INF=1e18;

static const ll MAX=101010;

static const ll MOD=1e9+7;



ll gcd(ll a, ll b) {

  if(b==0) return a;

  else return gcd(b, a%b);

}



ll lcm(ll a, ll b) {

  return a*b/gcd(a, b);

}





int main(void) {

  ll N, M;

  cin >> N >> M;

  ll a[MAX], b[MAX];

  ll cnt[MAX]={};

  ll i;

  

  for(i=0; i<N; i++) {

    cin >> a[i];

    b[i]=a[i]/2;

    

    ll t=b[i];

    while(t%2==0) {

      cnt[i]++;

      t/=2;

    }

    

  }

  sort(b, b+N);

  

  sort(cnt, cnt+N);

  if(cnt[0]!=cnt[N-1]) {

    pt(0);

    return 0;

  }

  

  ll L=1;

  for(i=0; i<N; i++) {

    L=lcm(L, b[i]);

  }

  

  pt((M/L+1)/2);

  

}


// Faster C++ solution for the same problem (measured speedup: 1.8332359433843206x):
// Author: HarshKumar



#include <bits/stdc++.h>

using namespace std;

#define ll int64_t

const ll N = 1e6 + 6, M = 1e9 + 7;

ll lcm(ll a, ll b)

{

    return a * b / __gcd(a, b);

}

int main()

{

    ios::sync_with_stdio(false), cin.tie(nullptr);

    ll n, m, l = 1;

    cin >> n >> m;

    vector<ll> a(n);

    for (ll &e : a)

        cin >> e, e /= 2, l = lcm(l, e);

    for (ll e : a)

    {

        ll x = l;

        while (e % 2 == 0)

            e /= 2, x /= 2;

        if (x % 2 == 0)

            return cout << 0, 0;

    }

    cout << m / l - m / (2 * l);

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

int main()

{

    char a, b;

    cin>>a>>b;

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

    else cout<<"D";





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.343905449040397x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<map>

using namespace std;

int main()

{

    char a,b;

    cin >> a >> b;

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

    else cout << "D" << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.356471117003809x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#include <iostream>

using namespace std;



int main(){

    string a,b;

    cin>>a>>b;

    if (a=="H"){

        if (b=="H"){

            cout<<"H";

        } else {

            cout<<"D";

        }

    } else {

        if (b=="H"){

            cout<<"D";

        } else {

            cout<<"H";

        }

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.356028711375209x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main(){

	string a,b;

	cin>>a>>b;

	if(a=="H" && b=="H"){

	cout<<"H\n";

}

	else if(a=="D"&&b=="D"){

	cout<<"H\n";

}

	else{

	cout<<"D\n";

}

}

// Faster C++ solution for the same problem (measured speedup: 5.398742662645552x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

	char a,b;

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

	if(a==b){

	  cout<<"H";

	  }

    else

       cout<<"D";

}

// Faster C++ solution for the same problem (measured speedup: 5.347431095984972x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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;









}

// Faster C++ solution for the same problem (measured speedup: 5.398918384985656x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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";

}

// Faster C++ solution for the same problem (measured speedup: 5.340956609434377x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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");

	}

	

	

	

}

// Faster C++ solution for the same problem (measured speedup: 5.295593751355696x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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";

}

}

// Faster C++ solution for the same problem (measured speedup: 5.343905449040397x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 5.344002083168018x):
#include <stdio.h>



int main(){

	char a, b;

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

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

	else puts("D");

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.340305975261159x):
#include<cstdio>

char a,b;

int main()

{

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

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

	else printf(" D");

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.341029775794141x):
#include<cstdio>

char a,b;

int main()

{

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

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

	else printf(" D");

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char a,b;

int main(){

    cin>>a>>b;

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

    else cout<<"D";

}

// Faster C++ solution for the same problem (measured speedup: 5.300566192588139x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.294149517274903x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.313225944754621x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.321063499752785x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.280761640584481x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

char m,n;

int main(){

	cin>>m>>n;

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

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

} 

// Faster C++ solution for the same problem (measured speedup: 5.300434518206992x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	char a,b;

	cin>>a>>b;

	if(a==b)

	{

		cout<<"H";

	}

	else

	{

		cout<<"D";

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.300043381488018x):
#include <cstdio>

char a,b;

int main ()

{

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

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

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.309028803212893x):
#include<cstdio>

//#include<Hatsune_Miku>

char a,b;

int main(){

    a=getchar();getchar();b=getchar();

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

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.337557347917081x):
#include <cstdio>

int main(){

    char a,b;

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

    std::puts(a==b?"H":"D");

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.35705207215727x):
#include <cstdio>

int main(){

    char a,b;

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

    std::puts(a==b?"H":"D");

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.338235379490371x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.357732580151454x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.599517033299563x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.343790940646398x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.331255018924932x):
#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;

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 5.237099837700522x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.121645950909797x):
#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;

}