#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<stdlib.h>
#define rep(i,s,t) for (i=s;i<=t;i++)
using namespace std;
double a[30][3];
bool vis[30];
int i,j,m,n,k,l,o,p;
double ans,temp;
inline double sqr(double x)
{
	return x*x;
}
inline double dist(int x,int y)
{
	return (sqr(a[x][0]-a[y][0])+sqr(a[x][1]-a[y][1])+sqr(a[x][2]-a[y][2]));
}
void dfs(int k,int s)
{
	if (s == m)
	{
		if (ans < temp) ans = temp;
		return;
	}
	if (k > n) return;
	double st;
	int i;
	rep(i,k,n)
	{
		vis[i] = true;
		st = temp;
		rep(j,1,i-1) if (vis[j]) temp+=dist(i,j);
		dfs(i+1,s+1);
		temp = st;
		vis[i] = false;
	}
	dfs(i+1,s);
}
int main()
{
	while (scanf("%d%d",&n,&m) != EOF)
	{
	
	rep(i,1,n) scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);
	ans = 0;
	temp = 0;
	dfs(1,0);
	printf("%.20f\n",ans);
	}
	return 0;
}