#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  long* x = new long[1000];
  long* y = new long[1000];
  long* z = new long[1000];
  for(int i=0;i<n;i++){
    cin >> x[i];
    cin >> y[i];
    cin >> z[i];
  }
  long score = 0;
  long* ord = new long[1000];
  for(int type=0;type<8;type++){
    for(int i=0;i<n;i++){
      ord[i] = x[i]*((type/4)*2-1) + y[i]*(((type%4)/2)*2-1) + z[i]*((type%2)*2-1);
    }
    sort(ord,ord+n);
    long cand = 0;
    for(int i=0;i<m;i++) cand += ord[n-1-i];
    score = max(score,cand);
  }
  cout << score << endl;
  return 0;
}
