import sys

sys.setrecursionlimit(1000000)

def maxcost(li,n,i,strt,dp):

    if i==(n-1):

        return li[i][strt]

    mx=-sys.maxsize

    for l in range(3):

        if l!=strt:

            if dp[i+1][l]==-1:

                cost=maxcost(li,n,i+1,l,dp)

                dp[i+1][l]=cost

            else:

                cost=dp[i+1][l]

            mx=max(mx,cost+li[i][strt])

    return mx





n=int(eval(input()))

li=[]

for i in range(n):

    temp=[int(x) for x in input().split()]

    li.append(temp)

dp=[[-1 for j in range(3)] for i in range(n)]

print((max(maxcost(li,n,0,0,dp),maxcost(li,n,0,1,dp),maxcost(li,n,0,2,dp))))
import sys

def maxcost(li,n):

    dp=[[-1 for j in range(3)] for i in range(n)]

    dp[n-1][0],dp[n-1][1],dp[n-1][2]=li[n-1][0],li[n-1][1],li[n-1][2]

    for i in range(n-2,-1,-1):

        for j in range(3):

            mx=-sys.maxsize

            for k in range(3):

                if j!=k:

                    mx=max(mx,dp[i+1][k]+li[i][j])

            dp[i][j]=mx

    return max(dp[0][0],dp[0][1],dp[0][2])



n=int(eval(input()))

li=[]

for i in range(n):

    temp=[int(x) for x in input().split()]

    li.append(temp)

print((maxcost(li,n)))
import sys

sys.setrecursionlimit(1000000)


def maxcost(li, n, i, strt, dp):
    if i == (n - 1):
        return li[i][strt]
    mx = -sys.maxsize
    for l in range(3):
        if l != strt:
            if dp[i + 1][l] == -1:
                cost = maxcost(li, n, i + 1, l, dp)
                dp[i + 1][l] = cost
            else:
                cost = dp[i + 1][l]
            mx = max(mx, cost + li[i][strt])
    return mx


n = int(eval(input()))
li = []
for i in range(n):
    temp = [int(x) for x in input().split()]
    li.append(temp)
dp = [[-1 for j in range(3)] for i in range(n)]
print(
    (max(maxcost(li, n, 0, 0, dp), maxcost(li, n, 0, 1, dp), maxcost(li, n, 0, 2, dp)))
)

import sys


def maxcost(li, n):
    dp = [[-1 for j in range(3)] for i in range(n)]
    dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] = li[n - 1][0], li[n - 1][1], li[n - 1][2]
    for i in range(n - 2, -1, -1):
        for j in range(3):
            mx = -sys.maxsize
            for k in range(3):
                if j != k:
                    mx = max(mx, dp[i + 1][k] + li[i][j])
            dp[i][j] = mx
    return max(dp[0][0], dp[0][1], dp[0][2])


n = int(eval(input()))
li = []
for i in range(n):
    temp = [int(x) for x in input().split()]
    li.append(temp)
print((maxcost(li, n)))

-sys.setrecursionlimit(1000000) - -def maxcost(li, n, i, strt, dp): -    if i == (n - 1): -        return li[i][strt] -    mx = -sys.maxsize -    for l in range(3): -        if l != strt: -            if dp[i + 1][l] == -1: -                cost = maxcost(li, n, i + 1, l, dp) -                dp[i + 1][l] = cost -            else: -                cost = dp[i + 1][l] -            mx = max(mx, cost + li[i][strt]) -    return mx +def maxcost(li, n): +    dp = [[-1 for j in range(3)] for i in range(n)] +    dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] = li[n - 1][0], li[n - 1][1], li[n - 1][2] +    for i in range(n - 2, -1, -1): +        for j in range(3): +            mx = -sys.maxsize +            for k in range(3): +                if j != k: +                    mx = max(mx, dp[i + 1][k] + li[i][j]) +            dp[i][j] = mx +    return max(dp[0][0], dp[0][1], dp[0][2]) -dp = [[-1 for j in range(3)] for i in range(n)] -print( -    (max(maxcost(li, n, 0, 0, dp), maxcost(li, n, 0, 1, dp), maxcost(li, n, 0, 2, dp))) -) +print((maxcost(li, n)))