console.log((args=>{
  const [[N,M],...tmp] = args.trim().split('\n').map(r=>r.split(' ').map(v=>parseInt(v)));
  const dp = Array.from({length:N+1},_=>Array.from({length:M+1},_=>Array(8).fill(-Infinity)));
  dp[0][0] = [0,0,0,0,0,0,0,0];
  for ( let i = 0; i < N; i++ ) {
    const [x,y,z] = tmp[i];
    dp[i+1][0] = [0,0,0,0,0,0,0,0];
    for ( let j = 0; j < M; j++ ) {
      for ( let b = 0; b < 8; b++ ) {
        let s = 0;
        s += (b&1)?x:-x;
        s += (b&2)?y:-y;
        s += (b&4)?z:-z;
        dp[i+1][j+1][b] = Math.max( dp[i][j+1][b], dp[i][j][b] + s );
      }
    }
  }
  return `${Math.max(...dp[N][M])}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
