N = int(eval(input()))

act = list(list(map(int, input().split())) for _ in range(N))

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

for i in range(N):

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

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

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

print((max(dp[N])))
import sys

input = sys.stdin.readline

N = int(eval(input()))

act = [tuple(map(int, input().split())) for _ in range(N)]

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

dp[0][0] = act[0][0]

dp[0][1] = act[0][1]

dp[0][2] = act[0][2]

for i in range(N - 1):

  for j in range(3):

    dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]

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

import sys

input = sys.stdin.readline
N = int(eval(input()))
act = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[0][2]
for i in range(N - 1):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]
print((max(dp[-1])))

+import sys + +input = sys.stdin.readline -act = list(list(map(int, input().split())) for _ in range(N)) -dp = [[0 for _ in range(3)] for _ in range(N + 1)] -for i in range(N): -    dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2])) -    dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2])) -    dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1])) -print((max(dp[N]))) +act = [tuple(map(int, input().split())) for _ in range(N)] +dp = [[0] * 3 for _ in range(N)] +dp[0][0] = act[0][0] +dp[0][1] = act[0][1] +dp[0][2] = act[0][2] +for i in range(N - 1): +    for j in range(3): +        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j] +print((max(dp[-1])))