module solution;
import core.bitop, std.algorithm, std.stdio, std.range;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		alias Cake = long [3];
		auto a = new Cake [n];
		foreach (ref c; a)
		{
			readf (" %s %s %s", &c[0], &c[1], &c[2]);
		}
		long res = 0;
		foreach (i; 0..8)
		{
			a.schwartzSort !(c => c[0] + c[1] + c[2], q{a > b});
			long cur = 0;
			foreach (ref c; a.take (m))
			{
				if (c[0] + c[1] + c[2] > 0)
				{
					cur += c[0] + c[1] + c[2];
				}
			}
			res = max (res, cur);

			int q = bsf (i + 1);
			if (q >= 3)
			{
				break;
			}
			foreach (ref c; a)
			{
				c[q] *= -1;
			}
		}
		writeln (res);
	}
}
