#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int64_t n, m;
	cin >> n >> m;
	int64_t x[n], y[n], z[n];
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i];
	}
	int64_t ans = 0;
	for (int i = 0; i < (1 << 3); i++)
	{
		int64_t val[n];
		for (int j = 0; j < n; j++)
		{
			val[j] = x[j] * ((i & 1) ? -1 : 1) + y[j] * ((i & 2) ? -1 : 1) + z[j] * ((i & 4) ? -1 : 1);
		}
		sort(val, val + n);
		reverse(val, val + n);
		ans = max(ans, accumulate(val, val + m, int64_t(0)));
	}
	cout << ans << endl;
	return 0;
}