#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

inline double square(double x) { return x * x; }
int n, m;
double color[1000][3];
int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    REP(i, n) {
      REP(k, 3) {
        scanf("%lf", &color[i][k]);
      }
    }
    double ans = 0.0;
    REP(bits, 1 << n) {
      if (__builtin_popcount(bits) != m) { continue; }
      double lans = 0.0;
      REP(i, n) {
        if (!((bits >> i) & 1)) { continue; }
        REP(j, i) {
          if (!((bits >> j) & 1)) { continue; }
          REP(k, 3) {
            lans += square(color[i][k] - color[j][k]);
          }
        }
      }
      ans = max(ans, lans);
    }
    printf("%.8f\n", ans);
  }
}