//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int n, m;
    ll p1[1000], p2[1000], p3[1000], p4[1000], p5[1000], p6[1000], p7[1000], p8[1000];
    ll x, y, z;
    cin >> n >> m;
    REP(i, n) {
        cin >> x >> y >> z;
        p1[i] = x + y + z;
        p2[i] = -x + y + z;
        p3[i] = x - y + z;
        p4[i] = -x - y + z;
        p5[i] = x + y - z;
        p6[i] = -x + y - z;
        p7[i] = x - y - z;
        p8[i] = -x - y - z;
    }
    sort(p1, p1 + n, greater<ll>());
    sort(p2, p2 + n, greater<ll>());
    sort(p3, p3 + n, greater<ll>());
    sort(p4, p4 + n, greater<ll>());
    sort(p5, p5 + n, greater<ll>());
    sort(p6, p6 + n, greater<ll>());
    sort(p7, p7 + n, greater<ll>());
    sort(p8, p8 + n, greater<ll>());
    ll max = -100000000000000;
    ll p1_max = accumulate(p1, p1+m, 0LL);
    ll p2_max = accumulate(p2, p2+m, 0LL);
    ll p3_max = accumulate(p3, p3+m, 0LL);
    ll p4_max = accumulate(p4, p4+m, 0LL);
    ll p5_max = accumulate(p5, p5+m, 0LL);
    ll p6_max = accumulate(p6, p6+m, 0LL);
    ll p7_max = accumulate(p7, p7+m, 0LL);
    ll p8_max = accumulate(p8, p8+m, 0LL);

    if(max < p1_max) max = p1_max;
    if(max < p2_max) max = p2_max;
    if(max < p3_max) max = p3_max;
    if(max < p4_max) max = p4_max;
    if(max < p5_max) max = p5_max;
    if(max < p6_max) max = p6_max;
    if(max < p7_max) max = p7_max;
    if(max < p8_max) max = p8_max;

    cout << max;

    return 0;
}


Measured memory_bytes: 256