n=int(eval(input()))

dp=[[0]*(n) for _ in range(3)]

l=[]

for i in range(n):

    a,b,c=list(map(int,input().split()))

    l.append([a,b,c])

dp[0][0],dp[1][0],dp[2][0]=l[0][0],l[0][1],l[0][2]

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

    dp[0][i+1]=max(dp[1][i]+l[i+1][0],dp[2][i]+l[i+1][0])

    dp[1][i+1]=max(dp[0][i]+l[i+1][1],dp[2][i]+l[i+1][1])

    dp[2][i+1]=max(dp[0][i]+l[i+1][2],dp[1][i]+l[i+1][2])

print((max([dp[0][n-1],dp[1][n-1],dp[2][n-1]])))

import sys

input=sys.stdin.readline



n=int(eval(input()))

dp=[[0]*3  for _ in range(n)]

a,b,c=list(map(int,input().split()))

dp[0]=[a,b,c]

for i in range(1,n):

    a,b,c=list(map(int,input().split()))

    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a

    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b

    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c

print((max(dp[n-1])))

n = int(eval(input()))
dp = [[0] * (n) for _ in range(3)]
l = []
for i in range(n):
    a, b, c = list(map(int, input().split()))
    l.append([a, b, c])
dp[0][0], dp[1][0], dp[2][0] = l[0][0], l[0][1], l[0][2]
for i in range(0, n - 1):
    dp[0][i + 1] = max(dp[1][i] + l[i + 1][0], dp[2][i] + l[i + 1][0])
    dp[1][i + 1] = max(dp[0][i] + l[i + 1][1], dp[2][i] + l[i + 1][1])
    dp[2][i + 1] = max(dp[0][i] + l[i + 1][2], dp[1][i] + l[i + 1][2])
print((max([dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]])))

import sys

input = sys.stdin.readline
n = int(eval(input()))
dp = [[0] * 3 for _ in range(n)]
a, b, c = list(map(int, input().split()))
dp[0] = [a, b, c]
for i in range(1, n):
    a, b, c = list(map(int, input().split()))
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
print((max(dp[n - 1])))

+import sys + +input = sys.stdin.readline -dp = [[0] * (n) for _ in range(3)] -l = [] -for i in range(n): +dp = [[0] * 3 for _ in range(n)] +a, b, c = list(map(int, input().split())) +dp[0] = [a, b, c] +for i in range(1, n): -    l.append([a, b, c]) -dp[0][0], dp[1][0], dp[2][0] = l[0][0], l[0][1], l[0][2] -for i in range(0, n - 1): -    dp[0][i + 1] = max(dp[1][i] + l[i + 1][0], dp[2][i] + l[i + 1][0]) -    dp[1][i + 1] = max(dp[0][i] + l[i + 1][1], dp[2][i] + l[i + 1][1]) -    dp[2][i + 1] = max(dp[0][i] + l[i + 1][2], dp[1][i] + l[i + 1][2]) -print((max([dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]]))) +    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a +    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b +    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c +print((max(dp[n - 1])))