#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<double>> lab(n, vector<double>(3));
    REP(i, n) {
        cin >> lab[i][0] >> lab[i][1] >> lab[i][2];
    }

    double ma = 0;
    REP(x, 1<<n) {
        if (__builtin_popcount(x) == m) {
            double val = 0;
            REP(i, n) FOR(j, i+1, n) {
                if (BIT(x, i) && BIT(x, j)) {
                    REP(k, 3) val += SQ(lab[i][k] - lab[j][k]);
                }
            }
            ma = max(ma, val);
        }
    }
    printf("%.20f\n", ma);
}