import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

struct Cake {
    long x, y, z;
}

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

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

void main() {
    solve();
    readln;
}