#include <cstdio>
#include <string>
#include <ctime>
#include <vector>
#include <iterator>
#include <algorithm> // #include <iostream> // using namespace std; srand(time(NULL))
#include <iostream>

std::vector<long long> compare (std::vector<long long> n1, std::vector<long long> n2){
    std::vector<long long> compare_result;
    
    std::size_t n1_size = n1.size();
    std::size_t n2_size = n2.size();

    // n1について，n2におけるどの位置に値するかを記録しておくvector配列
    std::vector<int> n1_iterator(n1_size);

    bool forEnd = false;
    for(int i = 0; i < n1_size; i++){
        for(int j = 0; j < n2_size; j++){
            if(i ==0 && j == 0 && n1[n1_size - 1] <= n2[0]){
                n1_iterator[n1_size - 1] = 0;
                forEnd = true;
            }
            if(forEnd){
                break;  
            }
            if(n1[n1_size-1-i] <=n2[j]) {
                n1_iterator[n1_size-1-i] = j;
                break;
            }
            if(j == n2_size-1){
                n1_iterator[n1_size-1-i] = n2_size;
            }
        }
        if(forEnd){
            break;  
        }
    }

    // n1_which，n2_which：各々についてのiterator
    int n1_which = 0;
    int n2_which = 0;
    
    // n1_iteratorの末尾が0であるときに関して，n1_iteratorの全要素が0になるのでそれを代入する．
    if(n1_iterator[n1_size - 1] == 0){
        for(int j = 0; j <n1_size; j++){
            n1_iterator[j] = 0;
        }
    }

    while((n2_which <= n2_size - 1) || (n1_which <= n1_size - 1)){
        if(n1_which != n1_size) {
            if (n1_iterator[n1_which] > n2_which ){
                compare_result.push_back(n2[n2_which]);
                n2_which++;
            }
            else {
                compare_result.push_back(n1[n1_which]);
                n1_which++;
            }
        }
        else{
            compare_result.push_back(n2[n2_which]);
            n2_which++; 
        }
    }
    
    return compare_result;
}

std::vector<long long> merge (std::vector<long long> n){ // int merge (string *s, int N, std::vector<int> n){
    
    std::size_t n_size = n.size();
    if (n_size <= 2){
        if (n_size != 1) {
            if(n[0] > n[1]){
                int x = n[0];
                std::iter_swap(n.begin(),n.begin()+1);
            }
        } 
        return n;
    } else {
        std::vector<long long> n1,n2;
        copy(n.begin(), std::next(n.begin(), (int) n_size/2),back_inserter(n1));
        int xx = n_size /2;
        copy(std::next(n.begin(), xx), n.end(), back_inserter(n2));
        // return n2;
        return compare(merge(n1), merge(n2));
    }
}

int main(void){
    long long N, M;
    std::cin >> N >> M;
    // vector<vector<long long> > dp(N+1,vector<long long>(N+1) );

    std::vector<std::vector<long long> > number(8,std::vector<long long>(N));
    long long x,y,z;

    for (int i = 0; i < N; i++) {
        std::cin >> x >> y >> z;
        number[0][i] = x + y + z;
        number[1][i] = x - y + z;
        number[2][i] = x + y - z;
        number[3][i] = -1*x + y + z;
        number[4][i] = -1*x - y + z;
        number[5][i] = -1*x + y - z;
        number[6][i] = -1*x - y - z;
        number[7][i] = x - y - z;
    }
    long long answer = -1;
    long long subsubsub = 0;
    for (int i = 0; i < 8; i++) {
        std::vector<long long> main_answer = merge(number[i]);
        subsubsub = 0;
        for (int j = 0; j < M; j++) {
            subsubsub += main_answer[N-j-1];
        }
        if (subsubsub > answer) {
            answer = subsubsub;
        }
    }
    std::cout << answer << std::endl;;
    return 0;

}

Measured memory_bytes: 384