import Data.List
--import Data.Array
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

--type UArray Int Int = Haps
type DP s = STUArray s (Int,Int) Int

--i>=2
dp_i :: DP s -> Int -> ST s ()
dp_i dparr i = do
  [aj,bj,cj] <- forM [1..3] $ \j -> readArray dparr (i-1,j)
  [a,b,c]    <- forM [1..3] $ \j -> readArray dparr (i,j)
  writeArray dparr (i,1) $ (max bj cj)+a
  writeArray dparr (i,2) $ (max aj cj)+b
  writeArray dparr (i,3) $ (max bj aj)+c
solve :: [Int] -> Int -> Int
solve haps n = runST $ do
    dparr <- newListArray ((1,1),(n,3)) haps
    forM_ [2..n] $ dp_i dparr
    (forM [1..3] $ \j -> readArray dparr (n,j)) >>= return.maximum

main :: IO ()
main = do
  n <- read <$> getLine
  haps <- replicateM n $ map read <$> words <$> getLine :: IO [[Int]]
  putStrLn $ show $ solve (concat haps) n
