n, m = gets.split.map(&:to_i)
p m == 1 ? 0 : n.times.map{ gets.split.map(&:to_f) }.combination(m).map{  |a|
    a.combination(2).to_a.map{ |p, q|
      p.zip(q).reduce(0){ |sum, (c, d)| sum + (c - d) ** 2 }
    }.reduce(:+)
  }.max