#include <bits/stdc++.h>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<ll, int> ll_i;

ll INF = LLONG_MAX / 10;

int main() {
	int N, M; cin >> N >> M;
	vector<ll> a(N), b(N), c(N);
	rep(i, N) cin >> a[i] >> b[i] >> c[i];
	ll ma = 0;
	rep(S, 1<<3) {
		vector<ll> v(N);
		rep(i, N) {
			ll x = 0;
			if (S>>0 & 1) x += a[i]; else x -= a[i];
			if (S>>1 & 1) x += b[i]; else x -= b[i];
			if (S>>2 & 1) x += c[i]; else x -= c[i];
			v[i] = x;
		}
		sort(v.rbegin(), v.rend());
		ll sum = 0;
		rep(i, M) sum += v[i];
		ma = max(ma, sum);
	}
	cout << ma << endl;
}
