import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, M = sc.nextInt()
    val items = Array.ofDim[(Long, Long, Long)](N)
    (0 until N) foreach { i =>
      val x, y, z = sc.nextLong()
      items(i) = (x, y, z)
    }

    val ans = (for {
      x_p <- Seq(1, -1)
      y_p <- Seq(1, -1)
      z_p <- Seq(1, -1)
    } yield {
      Sorting.quickSort(items)(Ordering.by[(Long, Long, Long), Long] { case (x, y, z) =>
          x * x_p + y * y_p + z * z_p
      }.reverse)
      val x = items.take(M).map(_._1).sum
      val y = items.take(M).map(_._2).sum
      val z = items.take(M).map(_._3).sum
      abs(x) + abs(y) + abs(z)
    }).max

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}
