#include <iostream>

using namespace std;

int main(){
	
	int n, m, dosadnost = 0, k;
	
	double prosek, sum = 0, cvarak;
	
	cin >> n >> m;
	
	int a[n];
	 
	for(int i = 0; i < n; i++)
	{
		cin >>a[i];
		sum +=a[i];
		
	}
	
	prosek = sum/n;
	for(int i = 0; i< m; i++)
	{
		k = 0;
		
		for(int j = 0; j < n; j++)
		{
			cvarak = a[j] - prosek;
			
			if(cvarak < 0)
			{
				cvarak = -cvarak;
			}
			
			if(cvarak < (double)m/2)
			{
				if(i < a[j])
				{
					k++;
				}
			}
			else
			{
				if(i >= a[j])
				{
					k++;
				}
			}
		}
		
		dosadnost += k*(n-k);
	}
	
	cout << dosadnost;
	
	
	return 0;
}