INF = float('inf')

N = int(eval(input()))

H = [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):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

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



ans = 0

for i in range(3):

    ans = max(ans, dp[N][i])



print(ans)

N = int(eval(input()))

A = []

B = []

C = []

for i in range(N):

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

    A.append(a)

    B.append(b)

    C.append(c)

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

dp[0][0] = A[0]

dp[0][1] = B[0]

dp[0][2] = C[0]

for i in range(1, N):

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

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

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

print((max(dp[N-1][0], dp[N-1][1], dp[N-1][2])))
INF = float("inf")
N = int(eval(input()))
H = [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):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + H[i][k])
ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])
print(ans)

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

-INF = float("inf") -H = [list(map(int, input().split())) for _ in range(N)] -dp = [[0 for _ in range(3)] for _ in range(N + 1)] +A = [] +B = [] +C = [] -    for j in range(3): -        for k in range(3): -            if j == k: -                continue -            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + H[i][k]) -ans = 0 -for i in range(3): -    ans = max(ans, dp[N][i]) -print(ans) +    a, b, c = list(map(int, input().split())) +    A.append(a) +    B.append(b) +    C.append(c) +dp = [[0 for _ in range(3)] for _ in range(N)] +dp[0][0] = A[0] +dp[0][1] = B[0] +dp[0][2] = C[0] +for i in range(1, N): +    dp[i][0] = max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i]) +    dp[i][1] = max(dp[i - 1][0] + B[i], dp[i - 1][2] + B[i]) +    dp[i][2] = max(dp[i - 1][0] + C[i], dp[i - 1][1] + C[i]) +print((max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2])))