import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**8)



def chmax(a, b):

    if a < b:

        a = b

        return b

    return a



N = int(eval(input()))

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

dp = [list([0] * 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] = chmax(dp[i + 1][k], dp[i][j] + a[i][k])



ans = 0

for i in range(3):

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



print(ans)
N = int(eval(input()))

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

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

dp[1][0] = a

dp[1][1] = b

dp[1][2] = c

for i in range(2, N + 1):

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

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

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

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



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

input = sys.stdin.readline
sys.setrecursionlimit(10**8)


def chmax(a, b):
    if a < b:
        a = b
        return b
    return a


N = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(N)]
dp = [list([0] * 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] = chmax(dp[i + 1][k], dp[i][j] + a[i][k])
ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])
print(ans)

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

-import sys - -input = sys.stdin.readline -sys.setrecursionlimit(10**8) - - -def chmax(a, b): -    if a < b: -        a = b -        return b -    return a - - -a = [list(map(int, input().split())) for _ in range(N)] -dp = [list([0] * 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] = chmax(dp[i + 1][k], dp[i][j] + a[i][k]) -ans = 0 -for i in range(3): -    ans = max(ans, dp[N][i]) -print(ans) +dp = [[0 for _ in range(3)] for _ in range(N + 1)] +a, b, c = list(map(int, input().split())) +dp[1][0] = a +dp[1][1] = b +dp[1][2] = c +for i in range(2, N + 1): +    a, b, c = list(map(int, input().split())) +    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a) +    dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b) +    dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c) +print((max(dp[N])))