import Data.List

combs _ [] = []
combs 1 xs = [[x] | x <- xs]
combs n (x:xs) = [x:y | y <- combs (n-1) xs] ++ combs n xs

main = getContents >>= print . calender_colors . read' . lines
 where read' (nm:cs) = (map read (words nm), sort (map (map read . words) cs))

calender_colors :: ([Int],[[Double]]) -> Double
calender_colors ([n,m],cs)
 | m < 2 = 0.0
 | otherwise = maximum (map total cs')
 where
  cs' = combs (if m==2 then 1 else m) cs
  total cs = sum [distance c1 c2| c1<-cs, c2<-cs, c1<c2]
  distance [l1,a1,b1] [l2,a2,b2] = (l2-l1)^2 + (a2-a1)^2 + (b2-b1)^2