#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll X[1010],Y[1010],Z[1010];
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		cin >> X[i] >> Y[i] >> Z[i];
	}
	ll d[2] = {1,-1};
	vector<ll> v;
	ll ans = 0;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				ll sem = 0;
				for(int l=0;l<N;l++){
					v.push_back(d[i]*X[l]+d[j]*Y[l]+d[k]*Z[l]);
				}
				sort(v.begin(),v.end());
				reverse(v.begin(),v.end());
				for(int l=0;l<M;l++){
					sem += v[l];
				}
				ans = max(ans,sem);
				v.clear();
			}
		}
	}
	cout << ans << endl;
}