#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 23;
int n, m;
double dis[MAXN][MAXN];
double ans, x[MAXN], y[MAXN], z[MAXN];
bool use[MAXN];
int arr[MAXN];

void dfs(int dp)
{
	if(dp == m + 1)
	{
		double sum=0;
		for(int i=1;i<dp;i++)
			for(int j=i+1;j<dp;j++)
				sum += dis[arr[i]][arr[j]];
		ans = max(ans, sum);
		return;
	}
	for(int i=arr[dp-1]+1;i<=n;i++)	if(!use[i])
	{
		use[i] = 1;
		arr[dp] = i;
		dfs(dp + 1);
		use[i] = 0;
	}
}

double caldis(int i, int j)
{
	double dx = x[i] - x[j],
		   dy = y[i] - y[j],
		   dz = z[i] - z[j];
	return dx * dx + dy * dy + dz * dz;
}

int main()
{
	while(~scanf("%d %d", &n, &m))
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%lf %lf %lf", &x[i], &y[i], &z[i]);
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				dis[i][j] = caldis(i, j);
		ans = 0;
		memset(arr, 0, sizeof(arr));
		memset(use, 0, sizeof(use));
		dfs(1);
		printf("%.6lf\n", ans);
	}
	return 0;
}