// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>
#include <numeric>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

struct Val {
    ll x[3];
};

int N, M;
Val val[1000];

ll search ( int order[3], int depth ) {
    if( depth == 3 ) {
        ll ans[3] = { 0 };

        cout << order[0] << " " << order[1] << " " << order[2] << endl;
        rep(i, M) {
            rep(j, 3){
                ans[j] += val[i].x[j];
                cout << val[i].x[j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        
        return abs(ans[0]) + abs(ans[1]) + abs(ans[2]);
    }

    int idx = abs(order[depth])-1;
    if( order[depth] < 0 ) stable_sort(val, val+N, [&](auto x, auto y) { return x.x[idx] < y.x[idx]; });
    else stable_sort(val, val+N, [&](auto x, auto y) { return x.x[idx] > y.x[idx]; });

    return search(order, depth+1);
}

int sgn ( ll x ) {
    return x < 0 ? -1 : 1;
}

bool same_sign ( Val& x, Val& y ) {
    return sgn(x.x[0])*sgn(y.x[0]) == 1 &&
        sgn(x.x[1])*sgn(y.x[1]) == 1 &&
        sgn(x.x[2])*sgn(y.x[2]) == 1;
}

ll diff ( Val& x, Val& y ) {
    return (x.x[0] - y.x[0]) + (x.x[1] - y.x[1]) + (x.x[2] - y.x[2]);
}

int main()
{
    cin >> N >> M;
    rep(i, N) cin >> val[i].x[0] >> val[i].x[1] >> val[i].x[2];

    ll ans = 0;
    rep(x, 2) rep(y, 2) rep(z, 2) {
        ll c[3] = { 0 };
        c[0] = x == 0 ? -1 : 1;
        c[1] = y == 0 ? -1 : 1;
        c[2] = z == 0 ? -1 : 1;

        ll tmp[1000];
        rep(i, N) tmp[i] = c[0]*val[i].x[0] + c[1]*val[i].x[1] + c[2]*val[i].x[2];
        sort(tmp, tmp+N, greater<ll>());

        ll res = 0;
        rep(i, M) res += tmp[i];
        ans = max(ans, res);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256