#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, x, k=0, l=0, zbir=0;
	cin >> n >> m;
	vector <int> b(m, 0);
	vector <int> c(m, 0);
	vector <int> niz(n);
	vector <int> a(m);
	for(int i=0;i<n;i++)
		cin >> niz[i];
	for(int i=0;i<n;i++){
		x = niz[i];
		for(int j=0;j<x;j++)
			b[j] = b[j] + 1;
		for(int j=0;j<m-x;j++)
			c[n-1-j] = c[n-1-j]+1;
		for(int j=0;j<m;j++){
			if(b[j] > c[j])
				k++;
			else
				l++;
		}
		if(k > l){
			for(int j=0;j<m;j++){
				a[j] = c[j];
				b[j] = c[j];
			}
		}
		else{
			if(k < l || k == l){
			for(int j=0;j<m;j++){
				a[j] = b[j];
				c[j] = b[j];
			}
			}
		}
		k=0;
		l=0;
	}
	for(int j=0;j<m;j++)
		zbir = zbir + a[j] * (n-a[j]);
	cout << zbir << endl;
	return 0;
}