import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto M = RD!long;

	auto p = new long[8][](N);
	foreach (i; 0..N)
	{
		auto x = RD!long;
		auto y = RD!long;
		auto z = RD!long;
		foreach (j; 0..8)
		{
			p[i][j] += j & 0b001 ? x : -x;
			p[i][j] += j & 0b010 ? y : -y;
			p[i][j] += j & 0b100 ? z : -z;
		}
	}

	long ans;
	foreach (i; 0..8)
	{
		p.sort!((a, b) => a[i] > b[i])();
		long s;
		foreach (j; 0..M) s += p[j][i];
		ans = max(ans, s);
	}

	writeln(ans);
	stdout.flush();
}