fun main(args : Array<String>){
    val INF = 1000000000000000000L
    var (n,m) = readLine()!!.split(' ').map(String::toInt)
    var dp = Array(1111,{Array(1111,{LongArray(8,{-INF})}) })
    for(i in 0 until 8)dp[0][0][i] = 0

    for(i in 0 until n){
        val x = readLine()!!.split(' ').map(String::toLong)
        for(j in 0 until i+1){
            for(k in 0 until 8){
                if(dp[i][j][k] != -INF) {
                    var tmp = 0L
                    for (l in 0 until 3) {
                        if (k and (1.shl(l)) > 0){
                            tmp += x[l]
                        }
                        else{
                            tmp -= x[l]
                        }
                    }
                    dp[i+1][j][k] = Math.max(dp[i+1][j][k],dp[i][j][k])
                    dp[i+1][j+1][k] = Math.max(dp[i+1][j+1][k],dp[i][j][k]+tmp)
                }
            }
        }
    }

    var ans = -INF
    for(i in 0 until 8)ans = Math.max(ans,dp[n][m][i])

    println(ans)

}