#include <iostream>
#include <vector>
#include <math.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstdio>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define repi(i, a, b) for( int i = a; i < b; i++ )
typedef vector<int> vec;
#define eps 1e-10

struct C{
    double l, a, b;
};

int N, M;
double ans = 0;
vector<C> c;

double dist( C c1, C c2 ){
    return pow(c1.l - c2.l, 2) + pow(c1.a - c2.a, 2) + pow(c1.b - c2.b, 2);
}

void dfs( int d, vec v ){
    if( d == M ){
        double sum = 0;
        rep(i, v.size()) repi(j, i+1, v.size()){
            sum += dist(c[v[i]], c[v[j]]);
        }
        //cout << 'ans:' << ans << endl;
        ans = max( ans, sum );
    }else{
        repi(i, v[d-1]+1, N){
            v.push_back(i);
            dfs(d+1, v);
            v.pop_back();
        }
    }
}

int main(){
    cin >> N >> M;
    rep(i, N){
        C t;
        cin >> t.l >> t.a >> t.b;
        c.push_back(t);
    }
    vec v;

    rep(i, N){
        v.push_back(i);
        dfs(1, v);
        v.pop_back();
    }
    printf("%.20f\n", ans);
}