fun main(args: Array<String>) {
    val (N,M) = readLine()!!.split(" ").map { it.toInt() }
    val a = (1..N).map { readLine()!!.split(" ").map { it.toLong() } }
    val b = (0..7).map {
        val xp: Int = it % 2
        val yp: Int = (it/2)%2
        val zp: Int = (it/4)%2

        a.map {
            val x = if(xp==0) it[0] else -it[0]
            val y = if(yp==0) it[1] else -it[1]
            val z = if(zp==0) it[2] else -it[2]
            x + y + z
        }
                .sortedDescending()
                .subList(0, M)
                .sum()
    }.max()
    println(b)
}