#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
	int N, M, *O, *a, k = 1, i = 1, dos=0, levo=0, desno=0;
	cin >> N >> M;
	O = new int[M];
	a = new int[N];
	
	while (i<=M)
	{
		O[i] = 0;
		i++;
	}

	i = 1;
		while(i<=N)
		{
			cin >> a[i];
			if (a[i] != 0 && a[i] != M)
			{
				levo = levo + a[i];
				desno = desno + M - a[i];
			}
			i++;
		}
		i = 1;
		if (levo < desno)
		{

			while (i <= N)
			{

				k = 1;
				if (a[i] != 0 && a[i] != M)
				{
					while (k <= a[i])
					{
						O[k] = O[k] + 1;
						k++;
					}
				}
				i = i + 1;
			}
		}
		else
		{
			while (i <= N)
			{

				k = 1;
				if (a[i] != 0 && a[i] != M)
				{
					while (k <= M-a[i])
					{
						O[k] = O[k] + 1;
						k++;
					}
				}
				i = i + 1;
			}
		}

	i = 1;
	while (i <= M)
	{
		//cout << O[i];
		dos = dos + O[i] * (N - O[i]);
		i++;
	}
	cout << dos;
}