object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n,m = sc.nextInt()
  val a = Array.fill(n,3)(sc.nextLong())
  val a1 = a.map(ai=>ai(0)+ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a2 = a.map(ai=>ai(0)+ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a3 = a.map(ai=>ai(0)-ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a4 = a.map(ai=>ai(0)-ai(0)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a5 = a.map(ai=>(-1)*ai(0)+ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a6 = a.map(ai=>(-1)*ai(0)+ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a7 = a.map(ai=>(-1)*ai(0)-ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a8 = a.map(ai=>(-1)*ai(0)-ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  println(Array(a1,a2,a3,a4,a5,a6,a7,a8).max)
}