N = int(eval(input()))

A_B_C = []

for i in range(N):

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



DP = [[0]*3 for i in range(N)]



DP[0][0] = A_B_C[0][0]

DP[0][1] = A_B_C[0][1]

DP[0][2] = A_B_C[0][2]

for i in range(1, N):

    for j in range(3):

        j_a = (j + 1) % 3

        j_b = (j + 2) % 3

        DP[i][j] = max(DP[i-1][j_a], DP[i-1][j_b]) + A_B_C[i][j]



print((max(DP[N-1][0], DP[N-1][1], DP[N-1][2])))
N = int(eval(input()))

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



DP = [0] * 3



for f in F:

    D = [0] * 3

    S = {0, 1, 2}

    for i in range(3):

        S.remove(i)

        for s in S:

            D[i] = max(D[i], f[i] + DP[s])

        S.add(i)

    DP = D



print((max(DP)))
N = int(eval(input()))
A_B_C = []
for i in range(N):
    A_B_C.append(tuple(map(int, input().split())))
DP = [[0] * 3 for i in range(N)]
DP[0][0] = A_B_C[0][0]
DP[0][1] = A_B_C[0][1]
DP[0][2] = A_B_C[0][2]
for i in range(1, N):
    for j in range(3):
        j_a = (j + 1) % 3
        j_b = (j + 2) % 3
        DP[i][j] = max(DP[i - 1][j_a], DP[i - 1][j_b]) + A_B_C[i][j]
print((max(DP[N - 1][0], DP[N - 1][1], DP[N - 1][2])))

N = int(eval(input()))
F = [tuple(map(int, input().split())) for _ in range(N)]
DP = [0] * 3
for f in F:
    D = [0] * 3
    S = {0, 1, 2}
    for i in range(3):
        S.remove(i)
        for s in S:
            D[i] = max(D[i], f[i] + DP[s])
        S.add(i)
    DP = D
print((max(DP)))

-A_B_C = [] -for i in range(N): -    A_B_C.append(tuple(map(int, input().split()))) -DP = [[0] * 3 for i in range(N)] -DP[0][0] = A_B_C[0][0] -DP[0][1] = A_B_C[0][1] -DP[0][2] = A_B_C[0][2] -for i in range(1, N): -    for j in range(3): -        j_a = (j + 1) % 3 -        j_b = (j + 2) % 3 -        DP[i][j] = max(DP[i - 1][j_a], DP[i - 1][j_b]) + A_B_C[i][j] -print((max(DP[N - 1][0], DP[N - 1][1], DP[N - 1][2]))) +F = [tuple(map(int, input().split())) for _ in range(N)] +DP = [0] * 3 +for f in F: +    D = [0] * 3 +    S = {0, 1, 2} +    for i in range(3): +        S.remove(i) +        for s in S: +            D[i] = max(D[i], f[i] + DP[s]) +        S.add(i) +    DP = D +print((max(DP)))