#include <stdio.h>
#include <iostream>
#include <vector> 

using namespace std;

int main() {
	int m, n;
	cin >> n >> m;
	float pom = n;
	int N = n;
	int  uku = 0;
	vector<int> far(n);
	for (int i = 0; i < n; i++) {
		cin >> far[i];
		if (far[i] == m) {
			pom--;
			n--;
			i--;
		}
		else {
			uku += far[i];
		}
	}
	bool farbaj = uku / pom > m / 2.0;
	vector<vector<bool>> zid(N);
	for (int i = 0; i < n; i++) {
		zid[i].resize(m);
		for (int j = 0; j < far[i]; j++) {
			zid[i][j] = true;
		}
	}
	for (int i = n; i < N; i++) {
		zid[i].resize(m);
		for (int j = 0; j < far[i]; j++) {
			zid[i][j] = farbaj;
		}
	}

	int res = 0;
	for (int i = 0; i < m; i++) {
		int temp = 0;
		for (int j = 0; j < N; j++) {
			if (zid[j][i]) {
				temp++;
			}
		}
		res += temp * (N - temp);
	}
	cout << res;

}