#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Info{
	Info(){
		L = a = b = 0.0;
	}
	double L,a,b;
};


int main(){

	int N,M,limit,count;

	scanf("%d %d",&N,&M);

	int work[M],work_index;
	limit = pow(2,N);
	Info info[N];

	double maximum = 0.0,tmp_sum;

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].L,&info[i].a,&info[i].b);
	}

	for(int i = 0; i < limit; i++){
		count = 0;
		for(int k = 0; k < N; k++){
			if(i & (1 << k))count++;
		}
		if(count != M)continue;

		work_index = 0;
		for(int k = 0; k < N; k++){
			if(i & (1 << k)){
				work[work_index++] = k;
			}
		}

		tmp_sum = 0;

		for(int a = 0; a < work_index-1;a++){
			for(int b = a+1; b < work_index;b++){
				tmp_sum += (info[work[a]].L-info[work[b]].L)*(info[work[a]].L-info[work[b]].L)+(info[work[a]].a-info[work[b]].a)*(info[work[a]].a-info[work[b]].a)
						+(info[work[a]].b-info[work[b]].b)*(info[work[a]].b-info[work[b]].b);
			}
		}

		maximum = max(maximum,tmp_sum);
	}

	printf("%.10lf\n",maximum);

	return 0;
}