import Control.Monad
import qualified Data.Vector.Unboxed as UV
import Data.List
import qualified Data.ByteString.Char8 as B

r3 [a,b,c]=(a,b,c)
main = do
    n<-readLn::IO Int
    xs<-UV.replicateM n $ r3.unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    print $ f n xs
f n xs = (\(a,b,c)->maximum [a,b,c]) $ UV.foldl' p (0,0,0) xs where
    p (u,v,w) (a,b,c) = (a+max v w, b+max u w, c+max u v)
