#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
struct Cake{
    ll x, y, z;
    Cake(){}
    Cake(ll a, ll b, ll c){
        x = a, y = b, z = c;
    }
};
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll res = 0;
    ll tmp = 0;
    vector<Cake> A(N); 
    REP(i, N){
        ll x, y, z;
        cin >> x >> y >> z;
        A[i] = Cake(x, y, z);
    }

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (lhs.x + lhs.y + lhs.z) > (rhs.x + rhs.y + rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += A[i].x + A[i].y + A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (lhs.x + lhs.y - lhs.z) > (rhs.x + rhs.y - rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += A[i].x + A[i].y - A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (lhs.x - lhs.y + lhs.z) > (rhs.x - rhs.y + rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += A[i].x - A[i].y + A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (lhs.x - lhs.y - lhs.z) > (rhs.x - rhs.y - rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += A[i].x - A[i].y - A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (-lhs.x + lhs.y + lhs.z) > (-rhs.x + rhs.y + rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += -A[i].x + A[i].y + A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (-lhs.x + lhs.y - lhs.z) > (-rhs.x + rhs.y - rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += -A[i].x + A[i].y - A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (-lhs.x - lhs.y + lhs.z) > (-rhs.x - rhs.y + rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += -A[i].x - A[i].y + A[i].z;
    if(tmp> res) res = tmp;

    sort(ALL(A), [&](Cake &lhs, Cake &rhs){
        return (-lhs.x - lhs.y - lhs.z) > (-rhs.x - rhs.y - rhs.z);
    });
    tmp = 0;
    REP(i, M) tmp += -A[i].x - A[i].y - A[i].z;
    if(tmp> res) res = tmp;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256