import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.numeric;

void main() {
    const tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1];
    const xyzs = N.iota.map!(_ => readln.split.to!(long[])).array;

    cartesianProduct([-1,+1],[-1,+1],[-1,+1])
    .map!(signs =>
        xyzs.map!(xyz => dotProduct(xyz, [signs.expand]))
            .array
            .sort!((a,b) => a > b).take(M).sum)
    .reduce!max.writeln;
}

