#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<lint> x(N), y(N), z(N);
    repeat (i, N) cin >> x[i] >> y[i] >> z[i];
    
    if (M == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    const lint NEGINF = -1e18;
    //1
    vector<vector<lint>> ppp(N, vector<lint>(M + 1, NEGINF));
    ppp[0][1] = x[0] + y[0] + z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                ppp[n][m] = max(ppp[n-1][m-1] + x[n] + y[n] + z[n], ppp[n-1][m]);
            }
            else {
                ppp[n][m] = max(x[n] + y[n] + z[n], ppp[n-1][m]);
            }
        }
    }

    //2
    vector<vector<lint>> mpp(N, vector<lint>(M + 1, NEGINF));
    mpp[0][1] = - x[0] + y[0] + z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                mpp[n][m] = max(mpp[n-1][m-1] - x[n] + y[n] + z[n], mpp[n-1][m]);
            }
            else {
                mpp[n][m] = max( - x[n] + y[n] + z[n], mpp[n-1][m]);
            }
        }
    }
    
    
    //3
    vector<vector<lint>> pmp(N, vector<lint>(M + 1, NEGINF));
    pmp[0][1] = x[0] - y[0] + z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                pmp[n][m] = max(pmp[n-1][m-1] + x[n] - y[n] + z[n], pmp[n-1][m]);
            }
            else {
                pmp[n][m] = max(x[n] - y[n] + z[n], pmp[n-1][m]);
            }
        }
    }
    

    //4
    vector<vector<lint>> ppm(N, vector<lint>(M + 1, NEGINF));
    ppm[0][1] = x[0] + y[0] - z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                ppm[n][m] = max(ppm[n-1][m-1] + x[n] + y[n] - z[n], ppm[n-1][m]);
            }
            else {
                ppm[n][m] = max(x[n] + y[n] - z[n], ppm[n-1][m]);
            }
        }
    }
    
    
    //5
    vector<vector<lint>> mmp(N, vector<lint>(M + 1, NEGINF));
    mmp[0][1] = - x[0] - y[0] + z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                mmp[n][m] = max(mmp[n-1][m-1] - x[n] - y[n] + z[n], mmp[n-1][m]);
            }
            else {
                mmp[n][m] = max( - x[n] - y[n] + z[n], mmp[n-1][m]);
            }
        }
    }
    

    //6
    vector<vector<lint>> mpm(N, vector<lint>(M + 1, NEGINF));
    mpm[0][1] = - x[0] + y[0] - z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                mpm[n][m] = max(mpm[n-1][m-1] - x[n] + y[n] - z[n], mpm[n-1][m]);
            }
            else {
                mpm[n][m] = max( - x[n] + y[n] - z[n], mpm[n-1][m]);
            }
        }
    }
    
    
    //7
    vector<vector<lint>> pmm(N, vector<lint>(M + 1, NEGINF));
    pmm[0][1] = x[0] - y[0] - z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                pmm[n][m] = max(pmm[n-1][m-1] + x[n] - y[n] - z[n], pmm[n-1][m]);
            }
            else {
                pmm[n][m] = max(x[n] - y[n] - z[n], pmm[n-1][m]);
            }
        }
    }
    

    //8
    vector<vector<lint>> mmm(N, vector<lint>(M + 1, NEGINF));
    mmm[0][1] = - x[0] - y[0] - z[0];
    repeat_from_to (n, 1, N-1) {
        repeat_from_to (m, 1, M) {
            if (m != 1) {
                mmm[n][m] = max(mmm[n-1][m-1] - x[n] - y[n] - z[n], mmm[n-1][m]);
            }
            else {
                mmm[n][m] = max( - x[n] - y[n] - z[n], mmm[n-1][m]);
            }
        }
    }
    
    lint ans = ppp[N-1][M];
    ans = max(ans, ppm[N-1][M]);
    ans = max(ans, pmp[N-1][M]);
    ans = max(ans, mpp[N-1][M]);
    ans = max(ans, mmp[N-1][M]);
    ans = max(ans, mpm[N-1][M]);
    ans = max(ans, pmm[N-1][M]);
    ans = max(ans, mmm[N-1][M]);
    cout << ans << endl;
}

Measured memory_bytes: 63232