abc :: Int -> [[Int]] -> Int
abc 0 _  = 0
abc _ [] = 0
abc n ([a,b,c]:l) = maximum [c + (ab (n-1) l), b + (ac (n-1) l), a + (bc (n-1) l)]
ab :: Int -> [[Int]] -> Int
ab 0 _  = 0
ab _ [] = 0
ab n ([a,b,c]:l) = maximum [b + (ac (n-1) l), a + (bc (n-1) l)]
ac :: Int -> [[Int]] -> Int
ac 0 _  = 0
ac _ [] = 0
ac n ([a,b,c]:l) = maximum [c + (ab (n-1) l), a + (bc (n-1) l)]
bc :: Int -> [[Int]] -> Int
bc 0 _  = 0
bc _ [] = 0
bc n ([a,b,c]:l) = maximum [c + (ab (n-1) l), b + (ac (n-1) l)]

main :: IO ()
main = do
   n <- read <$> getLine
   l <- genio n
   putStrLn $ show $ abc n l

genio :: Int -> IO [[Int]]
genio 0 = return [[]]
genio n = do
  l <- map read.words <$> getLine 
  ls <- genio (n-1)
  return $ l:ls
