#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

///////////////////////////////////////////

int main(){

    int N,M; cin >> N >> M;
    vector<pair<pair<ll,ll>, ll>> feature(N);
    REP(i,N) cin >> feature[i].first.first >> feature[i].first.second >> feature[i].second;

    vector<ll> res1(N), res2(N), res3(N), res4(N), res5(N), res6(N), res7(N), res8(N);

    REP(i,N){
        // + + +
        res1[i] = feature[i].first.first + feature[i].first.second + feature[i].second;
        // - + +
        res2[i] = -1 * feature[i].first.first + feature[i].first.second + feature[i].second;
        // + - +
        res3[i] = feature[i].first.first - feature[i].first.second + feature[i].second;
        // + + -
        res4[i] = feature[i].first.first + feature[i].first.second - feature[i].second;
        // - - +
        res5[i] = -1 * feature[i].first.first - feature[i].first.second + feature[i].second;
        // - + -
        res6[i] = -1 * feature[i].first.first + feature[i].first.second - feature[i].second;
        // + - -
        res7[i] = feature[i].first.first - feature[i].first.second - feature[i].second;
        // - - -
        res8[i] = -1 * feature[i].first.first - feature[i].first.second - feature[i].second;
    }

    sort(res1.begin(), res1.end());
    sort(res2.begin(), res2.end());
    sort(res3.begin(), res3.end());
    sort(res4.begin(), res4.end());
    sort(res5.begin(), res5.end());
    sort(res6.begin(), res6.end());
    sort(res7.begin(), res7.end());
    sort(res8.begin(), res8.end());

    vector<ll> ans(8);

    ans[0]=accumulate(res1.begin(), res1.begin()+M, 0LL);
    ans[1]=accumulate(res2.begin(), res2.begin()+M, 0LL);
    ans[2]=accumulate(res3.begin(), res3.begin()+M, 0LL);
    ans[3]=accumulate(res4.begin(), res4.begin()+M, 0LL);
    ans[4]=accumulate(res5.begin(), res5.begin()+M, 0LL);
    ans[5]=accumulate(res6.begin(), res6.begin()+M, 0LL);
    ans[6]=accumulate(res7.begin(), res7.begin()+M, 0LL);
    ans[7]=accumulate(res8.begin(), res8.begin()+M, 0LL);

    ll output=0;

    REP(i,8){
        if(abs(ans[i])>output){
            output = abs(ans[i]);
        }
    }

    cout << output << endl;

    return 0;
}

Measured memory_bytes: 384