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

struct Cake {
    long x, y, z;
}

void solve() {
    int n, m;
    readf("%d %d\n", &n, &m);
    auto cakes = new Cake[n];
    foreach (ref c; cakes)
        readf("%d %d %d\n", &c.x, &c.y, &c.z);

    long res;
    foreach (k; 0..1<<3) {
        long[] a;
        foreach (cake; cakes) {
            long t;
            with (cake) {
                t += (k>>0 & 1 ? x : -x);
                t += (k>>1 & 1 ? y : -y);
                t += (k>>2 & 1 ? z : -z);
            }
            a ~= t;
        }
        sort!("a>b")(a);
        res = max(res, a[0..m].sum);
    }
    writeln(res);
}

void main() {
    solve();
}