#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
if m<2 then p 0;exit end
a=[];n.times{a.push(gets.split.map(&:to_f))}
p a.combination(m).map{|b|b.combination(2).map{|e|e[0].zip(e[1]).reduce(0){|s,e|s+=(e[1]-e[0])**2}}.reduce(&:+)}.max