#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int n, m;
double l[20], a[20], b[20];

vector<int> use;

// idx以降でk個選ぶときの最大値
double dfs(int idx, int k){
    double res = 0;
    if (k == 0){
        for (int i = 0; i < use.size(); i++)
        {
            for (int j = 0; j < i; j++)
            {
                double dl = l[use[i]] - l[use[j]];
                double da = a[use[i]] - a[use[j]];
                double db = b[use[i]] - b[use[j]];
                res += dl*dl + da*da + db*db;
            }
        }
    }
    else
    {
        for (int i = idx; i < n - k + 1; i++)
        {
            use.push_back(i);
            res = max(res, dfs(i+1, k - 1));
            use.pop_back();
        }
    }
    return res;
}

int main(){
    while (cin >> n >> m && n | m)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> l[i] >> a[i] >> b[i];
        }
        cout << fixed << setprecision(20) << dfs(0, m) << endl;
    }
}