import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

class Cake{
	BigInt x, y, z;
	BigInt v000, v001, v010, v011, v100, v101, v110, v111;
	this(string sx, string sy, string sz){
		x = BigInt(sx);
		y = BigInt(sy);
		z = BigInt(sz);
		v000 = x + y + z;
		v001 = x + y - z;
		v010 = x - y + z;
		v011 = x - y - z;
		v100 = -x + y + z;
		v101 = -x + y - z;
		v110 = -x - y + z;
		v111 = -x - y - z;
		}
	debug string toString(){
		return "x:" ~ x.to!string ~ " y:" ~ y.to!string ~ " z:" ~ z.to!string;
		}
	}

void main(){
	int n = read.to!int;
	int m = read.to!int;
	
	Cake[] cakes;
	foreach(i; 0 .. n){
		string[] s = readln.chomp.split;
		cakes ~= new Cake(s[0], s[1], s[2]);
		}
	
	debug cakes.writeln;
	
	BigInt ans = -1;
	BigInt sum;
	
	cakes.sort!"a.v000 > b.v000"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v000;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v001 > b.v001"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v001;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v010 > b.v010"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v010;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v011 > b.v011"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v011;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v100 > b.v100"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v100;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v101 > b.v101"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v101;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v110 > b.v110"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v110;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	cakes.sort!"a.v111 > b.v111"();
	debug cakes.writeln;
	sum = 0;
	foreach(cake; cakes[0 .. m]) sum += cake.v111;
	if(ans < sum) ans = sum;
	debug writeln("sum:", sum, " ans:", ans);
	
	ans.writeln;
	}