"use strict";

/**
 * Resolves problem.
 * @param  {string} input
 * @returns {string}
 */
var main = function(input) {
    const modes = [-1, 1];

    const params = input.split("\n");
    const M = params[0].split(" ").map(x => parseInt(x))[1];
    
    const cakes = params.slice(1)
        .map(cake => cake.split(" ").map(x => parseInt(x)));
    
    let max = 0;
    modes.forEach(i => {
        modes.forEach(j => {
            modes.forEach(k => {
                const s = cakes.map(x => x[0] * i + x[1] * j + x[2] * k)
                    .sort((a, b) => a - b)
                    .slice(0, M)
                    .reduce((a, b) => a + b, 0);
                const score = Math.abs(s);
                if (max < score)
                    max = score;
            })
        })
    });
    return max;
};

const output = main(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(output); // console.log outputs with trailing new line!
