import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Array.ST
import Data.Int

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  [x, y, z] <- transpose <$> replicateM n (map read . words <$> getLine) :: IO [[Int64]]
  print $ solve x y z m

inf :: Int64
inf = -10^18

solve :: [Int64] -> [Int64] -> [Int64] -> Int -> Int64
solve a b c m = maximum [maxsum (map (*i) a) (map (*j) b) (map (*k) c) m | i <- [-1, 1], j <- [-1, 1], k <- [-1, 1]]

maxsum :: [Int64] -> [Int64] -> [Int64] -> Int -> Int64
maxsum a b c m = runST $ do
  dp <- newArray (0, m) inf :: ST s (STUArray s Int Int64)
  writeArray dp 0 0
  forM_ (zip3 a b c) $ \(a, b, c) -> do
    forM_ [m, m - 1 .. 1] $ \i -> do
      max <$> readArray dp i <*> ((+) (a + b + c) <$> readArray dp (i - 1)) >>= writeArray dp i
  readArray dp m


