import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.Map.Lazy as M

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    ns <- replicateM n ((\[a,b,c]->(a,b,c)) . map (fst . fromJust . B.readInt) . B.words <$> B.getLine) :: IO [(Int,Int,Int)]

    let as = sum . take m . reverse . sort $ map (\(a,b,c)->sum [a , b , c]) ns
    let bs = sum . take m . reverse . sort $ map (\(a,b,c)->sum [a , b ,-c]) ns
    let cs = sum . take m . reverse . sort $ map (\(a,b,c)->sum [a ,-b , c]) ns
    let ds = sum . take m . reverse . sort $ map (\(a,b,c)->sum [a ,-b ,-c]) ns
    let es = sum . take m . reverse . sort $ map (\(a,b,c)->sum [-a, b , c]) ns
    let fs = sum . take m . reverse . sort $ map (\(a,b,c)->sum [-a, b ,-c]) ns
    let gs = sum . take m . reverse . sort $ map (\(a,b,c)->sum [-a,-b , c]) ns
    let hs = sum . take m . reverse . sort $ map (\(a,b,c)->sum [-a,-b ,-c]) ns
    print $ maximum [as,bs,cs,ds,es,fs,gs,hs]
