import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad


main :: IO ()
main = breads >>= main'
    where
        main' [n, m] = replicateM n breads >>= print . solve m 

solve :: Int -> [[Int]] -> Int 
solve m xs = maximum [calc (map f xs) | f <- mfs]
    where
        calc = sum . take m . sortBy (flip compare)
        mfs =
            [ (\[x, y, z] -> x + y + z)
            , (\[x, y, z] -> - x + y + z)
            , (\[x, y, z] -> x - y + z)
            , (\[x, y, z] -> - x - y + z)
            , (\[x, y, z] -> x + y - z)
            , (\[x, y, z] -> -x + y - z)
            , (\[x, y, z] -> x - y - z)
            , (\[x, y, z] -> - x - y - z)
            ]

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)