#include <iostream>
#include <algorithm>

using namespace std;

int *input(int n) {
	int *x = new int[n];
	for (int i = 0; i < n; i++)
		scanf("%d", x + i);
	return x;
}

int sum(int p, int q, int *x){
    int s = 0;
    for (int i = p; i <= q; i++)
        s += x[i];
    return s;
}

int main() {
	int n, m, *a, *t;
	cin >> n >> m;
	a = input(n);
	t = new int[m];
	for (int i = 0; i < m; i++)
		t[i] = i < a[0];
	for (int i = 1; i < n; i++) {
		int p, q;
		p = i * a[i] - 2 * sum(0, a[i] - 1, t);
		q = i * (m - (a[i])) - 2 * sum(a[i], m - 1, t);
		if(p < q)
		    for(int i = 0; i < a[i]; i++)
		        t[i]++;
		else
		    for(int i = a[i]; i < m; i++)
		        t[i]++;
	}
	
	int sum = 0;
	for (int i = 0; i < m; i++) 
		sum += t[i] * (n - t[i]);
	cout << sum;

	delete[] a;
	delete[] t;
	return 0;
}