from copy import deepcopy

n = int(eval(input()))

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



dp = [[float('-inf')] * 3 for _ in range(n)]



dp[0] = deepcopy(eff[0])



for i in range(1, n):

    for yi in range(3):

        for ti in range(3):

            if yi != ti:

                dp[i][ti] = max(dp[i][ti], dp[i-1][yi] + eff[i][ti])



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



da = db = dc = 0



for i in range(n):

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

    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c

print((max(da, db, dc)))
from copy import deepcopy

n = int(eval(input()))
eff = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("-inf")] * 3 for _ in range(n)]
dp[0] = deepcopy(eff[0])
for i in range(1, n):
    for yi in range(3):
        for ti in range(3):
            if yi != ti:
                dp[i][ti] = max(dp[i][ti], dp[i - 1][yi] + eff[i][ti])
print((max(dp[-1])))

n = int(eval(input()))
da = db = dc = 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c
print((max(da, db, dc)))

-from copy import deepcopy - -eff = [list(map(int, input().split())) for _ in range(n)] -dp = [[float("-inf")] * 3 for _ in range(n)] -dp[0] = deepcopy(eff[0]) -for i in range(1, n): -    for yi in range(3): -        for ti in range(3): -            if yi != ti: -                dp[i][ti] = max(dp[i][ti], dp[i - 1][yi] + eff[i][ti]) -print((max(dp[-1]))) +da = db = dc = 0 +for i in range(n): +    a, b, c = list(map(int, input().split())) +    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c +print((max(da, db, dc)))