fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(' ').map(String::toInt)
    val cakes = (1..N).map { readLine()!!.split(' ').map(String::toLong) }
    val r = (0..7).map {
        val x = if (it % 2 == 0) 1 else -1
        val y = if ((it shr 1) % 2 == 0) 1 else -1
        val z = if ((it shr 2) % 2 == 0) 1 else -1

        cakes
                .map {
                    (it[0] * x) + (it[1] * y) + (it[2] * z)
                }
                .sortedDescending()
                .take(M)
                .sum()
    }.max()
    println(r)
}