import sys

import numpy as np



n = int(eval(input()))

days = []

for _ in range(n):

    day = list(map(int, input().split()))

    days.append(day)

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



# 1日目

dp[0][0] = days[0][0]

dp[0][1] = days[0][1]

dp[0][2] = days[0][2]





for d in range(1,n):

    for i in range(3):

        mx = 0

        for j in range(3):

            if i != j:

                mx = max(dp[d-1][j] + days[d][i],mx)

                # mx = max(dp[d][i], dp[d-1][j]+ days[d][i])

        dp[d][i] = mx

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

n = int(eval(input()))

hh = []

for i in range(n):

    h = list(map(int, input().split()))

    hh.append(h)



c = [[0 for j in range(3)] for i in range(n)]

for i in range(3):

    c[0][i]  = hh[0][i]



for i in range(1,n):

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

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

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

print((max(c[-1])))

import sys
import numpy as np

n = int(eval(input()))
days = []
for _ in range(n):
    day = list(map(int, input().split()))
    days.append(day)
dp = [[10000] * 3 for _ in range(n)]
# 1日目
dp[0][0] = days[0][0]
dp[0][1] = days[0][1]
dp[0][2] = days[0][2]
for d in range(1, n):
    for i in range(3):
        mx = 0
        for j in range(3):
            if i != j:
                mx = max(dp[d - 1][j] + days[d][i], mx)
                # mx = max(dp[d][i], dp[d-1][j]+ days[d][i])
        dp[d][i] = mx
print((max(dp[-1])))

n = int(eval(input()))
hh = []
for i in range(n):
    h = list(map(int, input().split()))
    hh.append(h)
c = [[0 for j in range(3)] for i in range(n)]
for i in range(3):
    c[0][i] = hh[0][i]
for i in range(1, n):
    c[i][0] = max(c[i - 1][1], c[i - 1][2]) + hh[i][0]
    c[i][1] = max(c[i - 1][0], c[i - 1][2]) + hh[i][1]
    c[i][2] = max(c[i - 1][0], c[i - 1][1]) + hh[i][2]
print((max(c[-1])))

-import sys -import numpy as np - -days = [] -for _ in range(n): -    day = list(map(int, input().split())) -    days.append(day) -dp = [[10000] * 3 for _ in range(n)] -# 1日目 -dp[0][0] = days[0][0] -dp[0][1] = days[0][1] -dp[0][2] = days[0][2] -for d in range(1, n): -    for i in range(3): -        mx = 0 -        for j in range(3): -            if i != j: -                mx = max(dp[d - 1][j] + days[d][i], mx) -                # mx = max(dp[d][i], dp[d-1][j]+ days[d][i]) -        dp[d][i] = mx -print((max(dp[-1]))) +hh = [] +for i in range(n): +    h = list(map(int, input().split())) +    hh.append(h) +c = [[0 for j in range(3)] for i in range(n)] +for i in range(3): +    c[0][i] = hh[0][i] +for i in range(1, n): +    c[i][0] = max(c[i - 1][1], c[i - 1][2]) + hh[i][0] +    c[i][1] = max(c[i - 1][0], c[i - 1][2]) + hh[i][1] +    c[i][2] = max(c[i - 1][0], c[i - 1][1]) + hh[i][2] +print((max(c[-1])))