{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector (Int, Int, Int) -> Int
solve !n !m !xyzs = maximum $ map calcForPattern patterns
 where
  patterns = [ (b1, b2, b3) | b1 <- [1, -1], b2 <- [1, -1], b3 <- [1, -1] ]

  calcForPattern (!b1, !b2, !b3) =
    sum $ take m $ sortBy (flip compare) $ VU.toList $ VU.map
      (\(!x, !y, !z) -> x * b1 + y * b2 + z * b3)
      xyzs

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  xyzs <-
    VU.replicateM n
    $   (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  print $ solve n m xyzs
