#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, M;
vector<ll> x, y, z;
vector<tuple<ll, ll, ll>> xyz;
bool cmp1(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return get<0>(l)+get<1>(l)+get<2>(l) < get<0>(r)+get<1>(r)+get<2>(r);
}
bool cmp2(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return get<0>(l)+get<1>(l)-get<2>(l) < get<0>(r)+get<1>(r)-get<2>(r);
}
bool cmp3(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return get<0>(l)-get<1>(l)+get<2>(l) < get<0>(r)-get<1>(r)+get<2>(r);
}
bool cmp4(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return get<0>(l)-get<1>(l)-get<2>(l) < get<0>(r)-get<1>(r)-get<2>(r);
}
bool cmp5(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return -get<0>(l)+get<1>(l)+get<2>(l) < -get<0>(r)+get<1>(r)+get<2>(r);
}
bool cmp6(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return -get<0>(l)+get<1>(l)-get<2>(l) < -get<0>(r)+get<1>(r)-get<2>(r);
}
bool cmp7(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return -get<0>(l)-get<1>(l)+get<2>(l) < -get<0>(r)-get<1>(r)+get<2>(r);
}
bool cmp8(const tuple<ll, ll, ll> l, const tuple<ll, ll, ll> r){
  return -get<0>(l)-get<1>(l)-get<2>(l) < -get<0>(r)-get<1>(r)-get<2>(r);
}

int main(){
  cin >> N >> M;
  x.resize(N), y.resize(N), z.resize(N);
  REP(i, N){
    cin >> x[i] >> y[i] >> z[i];
    xyz.push_back(make_tuple(x[i], y[i], z[i]));
  }
  ll ans = 0;
  
  ll sumx, sumy, sumz;
  sort(xyz.begin(), xyz.end(), cmp1);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp2);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp3);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp4);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp5);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp6);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp7);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  sort(xyz.begin(), xyz.end(), cmp8);
  sumx = sumy = sumz = 0;
  for(int i = N-1; i >= N-M; i--){
    sumx+=get<0>(xyz[i]);
    sumy+=get<1>(xyz[i]);
    sumz+=get<2>(xyz[i]);
  }
  ans = max(ans, abs(sumx)+abs(sumy)+abs(sumz));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256