#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;

ll X[1000];
ll Z[1000];
ll Y[1000];
pll S[1000];
void _(){
    int n,m;
    cin >> n >>m;
    ll mx=0,x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        cin >> X[i] >> Y[i] >> Z[i];
    }
    for (int i = 0; i < n; ++i) {
        S[i]={X[i]+Y[i]+Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={X[i]+Y[i]-Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={X[i]-Y[i]-Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={X[i]-Y[i]+Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    //
    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={-X[i]+Y[i]+Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={-X[i]+Y[i]-Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={-X[i]-Y[i]-Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
        x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    x=0,y=0,z=0;
    for (int i = 0; i < n; ++i) {
        S[i]={-X[i]-Y[i]+Z[i],i};
    }
    sort(S,S+n,greater<pll>());
    for (int i = 0; i < m; ++i) {
       x+=X[S[i].second];y+=Y[S[i].second];z+=Z[S[i].second];
    }
    mx=max(abs(x)+abs(y)+abs(z),mx);

    cout << mx;




}



int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 256