unittest
{
	assert( [ "5 3", "3 1 4", "1 5 9", "2 6 5", "3 5 8", "9 7 9" ].solve == 56 );
	assert( [ "5 3", "1 -2 3", "-4 5 -6", "7 -8 -9", "-10 11 -12", "13 -14 15" ].solve == 54 );
	assert( [ "10 5", "10 -80 21", "23 8 38", "-94 28 11", "-26 -2 18", "-69 72 79", "-26 -86 -54", "-72 -50 59", "21 65 -32", "40 -94 87", "-62 18 82" ].solve == 638 );
	assert( [ "3 2", "2000000000 -9000000000 4000000000", "7000000000 -5000000000 3000000000", "6000000000 -1000000000 8000000000" ].solve == 30000000000 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto xyzs = new long[ 3 ][ n ];
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
	}
	
	auto ans = 0L;
	ans = max( ans, solve2( m, xyzs, [ +1L, +1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, +1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, -1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, -1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, +1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, +1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L, -1L ] ) );
	return ans;
}

auto solve2( long m, long[ 3 ][] xyzs, long[ 3 ] ss )
{
	auto ts = new long[ xyzs.length ];
	foreach( ref t, xyz; lockstep( ts, xyzs ) )
	{
		t += xyz[ 0 ] * ss[ 0 ] + xyz[ 1 ] * ss[ 1 ] + xyz[ 2 ] * ss[ 2 ];
	}
	ts.sort!( ( a, b ) => b < a );
	return ts[ 0 .. m ].sum;
}
