#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

struct data{
	LL x,y,z;
};

data p[1005];

bool cmp(data A,data B) {
	return A.x + A.y + A.z > B.x + B.y + B.z;
}
bool cmp2(data A,data B) {
	return -A.x + A.y + A.z > -B.x + B.y + B.z;
}
bool cmp3(data A,data B) {
	return A.x - A.y + A.z > B.x - B.y + B.z;
}
bool cmp4(data A,data B) {
	return -A.x - A.y + A.z > -B.x - B.y + B.z;
}
bool cmp5(data A,data B) {
	return A.x + A.y - A.z > B.x + B.y - B.z;
}
bool cmp6(data A,data B) {
	return -A.x + A.y - A.z > -B.x + B.y - B.z;
}
bool cmp7(data A,data B) {
	return A.x - A.y - A.z > B.x - B.y - B.z;
}
bool cmp8(data A,data B) {
	return -A.x - A.y -+ A.z > -B.x - B.y- B.z;
}

int main(){
	desperate_optimization(10);
	int N,M;
	cin>>N>>M;
	for(int i = 0;i <N;i++) cin>>p[i].x>>p[i].y>>p[i].z;
	LL answ = 0;
	LL totx = 0, toty = 0, totz = 0;
	sort(p,p+N,cmp);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx += p[i].x;
		toty += p[i].y;
		totz += p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);
	sort(p,p+N,cmp2);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx -= p[i].x;
		toty += p[i].y;
		totz += p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp3);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx += p[i].x;
		toty -= p[i].y;
		totz += p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp4);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx -= p[i].x;
		toty -= p[i].y;
		totz += p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp5);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx += p[i].x;
		toty += p[i].y;
		totz -= p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp6);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx -= p[i].x;
		toty += p[i].y;
		totz -= p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp7);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx += p[i].x;
		toty -= p[i].y;
		totz -= p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);

		sort(p,p+N,cmp8);
	totx = 0, toty = 0, totz = 0;
	for(int i = 0;i < M;i++) {
		totx -= p[i].x;
		toty -= p[i].y;
		totz -= p[i].z;
	}
	if(totx >= 0 && toty >= 0 && totz >= 0) answ = max(answ,totx + toty + totz);
	cout<<answ<<endl;
	
	return 0;
}


Measured memory_bytes: 256