import Data.List.Split
import Data.List
import Control.Monad

data Cake = Cake Int Int Int

val :: Cake -> Int
val (Cake a b c) = a + b + c

getMultipleInt :: IO [Int]
getMultipleInt = getLine >>= \x -> (return . (map read)) $ splitOn " " x

rec :: [Int] -> Cake
rec ls = Cake (ls !! 0) (ls !! 1) (ls !! 2)

solve :: [Cake] -> Int -> Bool -> Bool -> Bool -> Int
solve dat am x y z = (sum . (take am)) (sortBy (flip compare) calc)
    where
        calc = map val cakes'
        change a x = if x then -a else a
        cakes' = (flip map) dat $ \(Cake a b c) -> Cake (change a x) (change b y) (change c z)


main = do
    first <- getMultipleInt
    dat <- forM [1..(first !! 0)] $ \_ -> getMultipleInt
    let dat' = map rec dat
    let x = [True, False]
    let y = [True, False]
    let z = [True, False]
    let cand = [solve dat' (first !! 1) x' y' z' | x' <- x, y' <- y, z' <- z]
    putStrLn . show $ maximum cand