import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val scanner = new Scanner(in)
    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, m) =
        scanner.nextLine().split(" ").map(_.toInt)
      val point =
        Array.fill(n) {
          val Array(x, y, z) = scanner.nextLine().split(" ").map(_.toLong)
          (x, y, z)
        }

      val result = Seq(
        f(point, m, true, true, true),
        f(point, m, true, true, false),
        f(point, m, true, false, true),
        f(point, m, true, false, false),
        f(point, m, false, true, true),
        f(point, m, false, true, false),
        f(point, m, false, false, true),
        f(point, m, false, false, false)
      ).max

      output.println(result)
    }

    def f(ns: Array[(Long, Long, Long)], m: Int, xPositive: Boolean, yPositive: Boolean, zPositive: Boolean): Long = {
      val (x, y, z) = ns
        .sortBy { case (x, y, z) =>
          Seq(
            if (xPositive) x else -x,
            if (yPositive) y else -y,
            if (zPositive) z else -z
          ).sum
        }
        .take(m)
        .foldLeft((0L, 0L, 0L)) { case ((x, y, z), (xi, yi, zi)) =>
          (x + xi, y + yi, z + zi)
        }
      Seq(
        Math.abs(x),
        Math.abs(y),
        Math.abs(z)
      ).sum
    }
  }

}
