import Data.Array((!), listArray)
main = interact $ show.helper.(map read).words

helper (x:xs) = fonk x a 
            where a = listArray ((1, 1), (x, 3)) xs
                  fonk x a = maximum [f (1, aa)|aa<-[1..3]]  
                  f (i, j) 
                       | i == x = exc [a!(i, aa)|aa<-[1..3]] j
                       | otherwise =a!(i, j) +  
                                    exc [dp!(i+1, 1), dp!(i+1, 2), dp!(i+1, 3)] j
                  dp = listArray ((1, 1), (x, 3)) $ 
                       map f [(ii, jj)| ii<-[1..x], jj<-[1..3]]




exc (a1:a2:a3:_) 1 = max a2 a3
exc (a1:a2:a3:_) 2 = max a1 a3
exc (a1:a2:a3:_) 3 = max a2 a1
