N = int(eval(input()))

abc = []

for _ in range(N):

    abc.append(tuple(map(int, input().split())))



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

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

    for k in range(3):

        for last in range(3):

            if k != last:

                dp[i][k] = max(dp[i][k], dp[i-1][last] + abc[i-1][last])



ans = max(dp[N][k] for k in range(3))

print(ans)

N = int(eval(input()))



cur, nxt = [0] * 3, [0] * 3

for i in range(N):

    abc = [int(c) for c in input().split()]

    for k in range(3):

        for last in range(3):

            if k != last:

                nxt[k] = max(nxt[k], cur[last] + abc[k])



    cur = nxt

    nxt = [0] * 3



ans = max(cur[k] for k in range(3))

print(ans)

N = int(eval(input()))
abc = []
for _ in range(N):
    abc.append(tuple(map(int, input().split())))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(1, N + 1):
    for k in range(3):
        for last in range(3):
            if k != last:
                dp[i][k] = max(dp[i][k], dp[i - 1][last] + abc[i - 1][last])
ans = max(dp[N][k] for k in range(3))
print(ans)

N = int(eval(input()))
cur, nxt = [0] * 3, [0] * 3
for i in range(N):
    abc = [int(c) for c in input().split()]
    for k in range(3):
        for last in range(3):
            if k != last:
                nxt[k] = max(nxt[k], cur[last] + abc[k])
    cur = nxt
    nxt = [0] * 3
ans = max(cur[k] for k in range(3))
print(ans)

-abc = [] -for _ in range(N): -    abc.append(tuple(map(int, input().split()))) -dp = [[0] * 3 for _ in range(N + 1)] -for i in range(1, N + 1): +cur, nxt = [0] * 3, [0] * 3 +for i in range(N): +    abc = [int(c) for c in input().split()] -                dp[i][k] = max(dp[i][k], dp[i - 1][last] + abc[i - 1][last]) -ans = max(dp[N][k] for k in range(3)) +                nxt[k] = max(nxt[k], cur[last] + abc[k]) +    cur = nxt +    nxt = [0] * 3 +ans = max(cur[k] for k in range(3))