#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define vc vector
#define a first
#define b second
#define pb pusu_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

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

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

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

//MOD of Combination

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

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

//Union-Find Tree

int UFT_par[MAX];
int UFT_rank[MAX];

void UFT_init(int n){
  rep(i, 0, n){
    UFT_par[i] = i;
    UFT_rank[i] = 0;
  }
}

int UFT_find(int x){
  if(UFT_par[x] == x){
    return x;
  }else{
    return UFT_par[x] = UFT_find(UFT_par[x]);
  }
}

void UFT_unite(int x, int y){
  x = UFT_find(x);
  y = UFT_find(y);
  if(x == y) return;
  if(UFT_rank[x] < UFT_rank[y]){
    UFT_par[x] = y;
  }else{
    UFT_par[y] = x;
    if(UFT_rank[x] == UFT_rank[y]) UFT_rank[x]++;
  }
}

bool UFT_same(int x, int y){
  return UFT_find(x) == UFT_find(y);
}

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

bool comp(pii p, pii q){
  if(p.b == q.b) return p.a < q.a;
  return p.b < q.b;
}

void Main() {
  ll N, M; cin >> N >> M;
  vc<vc<ll>> VV(N, vc<ll>(3));
  rep(i, 0, N) rep(j, 0, 3) cin >> VV[i][j];
  vc<ll> V(N);
  ll res = 0;
  ll sum;
  //+++
  sum = 0;
  rep(i, 0, N) V[i] = VV[i][0] + VV[i][1] + VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //++-
  sum = 0;
  rep(i, 0, N) V[i] = VV[i][0] + VV[i][1] - VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //+-+
  sum = 0;
  rep(i, 0, N) V[i] = VV[i][0] - VV[i][1] + VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //+--
  sum = 0;
  rep(i, 0, N) V[i] = VV[i][0] - VV[i][1] - VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //-++
  sum = 0;
  rep(i, 0, N) V[i] = - VV[i][0] + VV[i][1] + VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //-+-
  sum = 0;
  rep(i, 0, N) V[i] = - VV[i][0] + VV[i][1] - VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //--+
  sum = 0;
  rep(i, 0, N) V[i] = - VV[i][0] - VV[i][1] + VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);
  //---
  sum = 0;
  rep(i, 0, N) V[i] = - VV[i][0] - VV[i][1] - VV[i][2];
  sort(all(V), greater<ll>());
  rep(i, 0, M) sum += V[i];
  chmax(res, sum);

  cout << res << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1920