#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)

main(){

  ll n,m;
  cin>>n>>m;
  using T3 = tuple<ll,ll,ll>;
  vector<T3> a;
  rep(i,n){
    ll x,y,z;cin>>x>>y>>z;
    a.emplace_back(x,y,z);
  }
  function<ll(T3)> sum = [](T3 const& elm)->ll{
    return get<0>(elm)+get<1>(elm)+get<2>(elm);
  };
  auto cmp = [&](T3 const& a,T3 const& b){
    return sum(a)<sum(b);
  };
  sort(a.begin(),a.end(),cmp);
  ll ans=-9999999999999,t1,t2;
  ll ax,ay,az,bx,by,bz;
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return -get<0>(elm)+get<1>(elm)+get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return get<0>(elm)-get<1>(elm)+get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return get<0>(elm)+get<1>(elm)-get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return -get<0>(elm)-get<1>(elm)-get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return -get<0>(elm)-get<1>(elm)+get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return -get<0>(elm)+get<1>(elm)-get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  sum = [](T3 const& elm)->ll{
    return get<0>(elm)-get<1>(elm)-get<2>(elm);
  };
  sort(a.begin(),a.end(),cmp);
  ax=ay=az=bx=by=bz=0;
  rep(i,m){
    ll x,y,z;
    tie(x,y,z)=a[i];
    ax+=x;
    ay+=y;
    az+=z;
    tie(x,y,z)=a[n-i-1];
    bx+=x;
    by+=y;
    bz+=z;
  }
  t1=abs(ax)+abs(ay)+abs(az);
  t2=abs(bx)+abs(by)+abs(bz);
  ans=max({ans,t1,t2});

  cout<<(ans)<<endl;

}

Measured memory_bytes: 256