#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m; double l[20], a[20], b[20];
int popcount(int x) {
	int ret = 0;
	for (int i = 0; i < 20; i++) {
		if (x & (1 << i)) ret++;
	}
	return ret;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &l[i], &a[i], &b[i]);
	double ret = 0.0;
	for (int i = 0; i < (1 << n); i++) {
		if (popcount(i) == m) {
			double res = 0.0;
			for (int j = 0; j < n; j++) {
				for (int k = j + 1; k < n; k++) {
					if ((i & (1 << j)) && (i & (1 << k))) {
						res += (l[j] - l[k]) * (l[j] - l[k]) + (a[j] - a[k]) * (a[j] - a[k]) + (b[j] - b[k]) * (b[j] - b[k]);
					}
				}
			}
			ret = max(ret, res);
		}
	}
	printf("%.9f\n", ret);
	return 0;
}