import javax.swing.ComboBoxEditor

fun main(args:Array<String>):Unit {
    val combinations = listOf(1, -1).flatMap{look ->
        listOf(1, -1).flatMap{taste ->
            listOf(1, -1).map{pop ->
                Combination(look.toLong(), taste.toLong(), pop.toLong())
            }
        }
    }
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val cakes = Array(n){
        val (x, y, z) = readLine()!!.trim().split(' ').map(String::toLong)
        Cake(x, y, z)
    }
    val max = combinations.mapNotNull{combinator ->
        val memo:Array<Combination?> = Array(m + 1){null}
        memo[0] = combinator
        for (cake in cakes) for (i in (m downTo 1)){
            if (memo[i - 1] != null) {
                if (memo[i] == null) {
                    memo[i] = memo[i - 1]!!.add(cake)
                }else if (memo[i - 1]!!.add(cake) > memo[i]!!) {
                        memo[i] = memo[i - 1]!!.add(cake)
                    }
                }
            }
        memo[m]?.sum()
        }.max()!!

    println(max)
}
data class Cake(val look:Long, val taste:Long, val popular:Long) {
    operator fun plus(other:Cake):Cake = Cake(look + other.look, taste + other.taste, popular + other.popular)
}
open class Combination private constructor (private val mLook:Long, private val mTaste:Long, private val mPopular:Long, private var mCake:Cake):Comparable<Combination>{
    override fun compareTo(other: Combination): Int {
        return sum().compareTo(other.sum())
    }
    open fun sum():Long = mLook * mCake.look + mTaste * mCake.taste + mPopular * mCake.popular
    fun add(cake: Cake):Combination {
        return Combination(mLook, mTaste, mPopular, cake + mCake)
    }

    constructor(look:Long, taste:Long, pop:Long):this(look, taste, pop, Cake(0, 0, 0))
}

object Dummy:Combination(0, 0, 0){
    override fun sum():Long = -1000000000000
}