#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;

typedef long long LL;
const int INF =2147483647;
LL qread(){
	LL w=1,c,ret;
	while((c=getchar())> '9'||c< '0')
	w=(c=='-'?-1:1); ret=c-'0';
	while((c=getchar())>='0'&&c<='9')
	ret=ret*10+c-'0';
	return ret*w;
}
const int MAXN =1e3+3;
LL ans,n,m,P[MAXN],A[MAXN],B[MAXN],C[MAXN];
void calc(){
	LL tmp=0; sort(P+1,P+1+n);
	dn(n,n-m+1,i) tmp+=P[i];
	ans=max(ans,tmp);
}
int main(){
	n=qread(),m=qread();
	up(1,n,i) A[i]=qread(),B[i]=qread(),C[i]=qread();
	up(0,1,k1) up(0,1,k2) up(0,1,k3){
		up(1,n,i) P[i]=A[i]*(k1?1:-1)+B[i]*(k2?1:-1)+C[i]*(k3?1:-1);
		calc();
	} 
	printf("%lld\n",ans);
	return 0;
}
