#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using Int = long long;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<Int> X(N), Y(N), Z(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> Z[i];
    Int result = 0;
    for (int i = 0; i < 8; i++) {
        vector<Int> P(N);
        for (int j = 0; j < N; j++) {
            P[j] = (i&1 ? 1 : -1) * X[j] + (i&2 ? 1 : -1) * Y[j] + (i&4 ? 1 : -1) * Z[j];
        }
        sort(P.rbegin(), P.rend());
        result = max(result, accumulate(P.begin(), P.begin()+M, 0LL));
    }
    cout << result << endl;
    return 0;
}