n = int(eval(input()))

a_ls = [0] * n

b_ls = [0] * n

c_ls = [0] * n

for i in range(n):

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

    a_ls[i] = a

    b_ls[i] = b

    c_ls[i] = c



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

dp[1] = [a_ls[0], b_ls[0], c_ls[0]]

for i in range(1,n):

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

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

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



print((max(dp[-1])))
n = int(eval(input()))

days_ls = [0] * n

for i in range(n):

    days_ls[i] = list(map(int, input().split()))



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

dp[0] = days_ls[0]

for i in range(1,n):

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

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

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

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

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

-a_ls = [0] * n -b_ls = [0] * n -c_ls = [0] * n +days_ls = [0] * n -    a, b, c = list(map(int, input().split())) -    a_ls[i] = a -    b_ls[i] = b -    c_ls[i] = c -dp = [[0] * 3 for _ in range(n + 1)] -dp[1] = [a_ls[0], b_ls[0], c_ls[0]] +    days_ls[i] = list(map(int, input().split())) +dp = [[0] * 3 for _ in range(n)] +dp[0] = days_ls[0] -    dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a_ls[i], dp[i][2] + a_ls[i]) -    dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b_ls[i], dp[i][2] + b_ls[i]) -    dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c_ls[i], dp[i][1] + c_ls[i]) +    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + days_ls[i][0] +    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + days_ls[i][1] +    dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + days_ls[i][2]