import numpy as np

N=int(eval(input()))

ABC=[]

for i in range(N):

    ABC.append(list(map(int,input().split())))

dp=[[0,0,0] for i in range(N)]

dp[0]=ABC[0]

for i in range(1,N):

    for j in range(3):

        dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+ABC[i][j]

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

ABC=[]

for i in range(N):

    ABC.append(list(map(int,input().split())))

Happy=[[0,0,0] for i in range(N)]

Happy[0]=ABC[0]

for i in range(1,N):

    for j in range(3):

        if j==0:

            Happy[i][j]=max(Happy[i-1][1],Happy[i-1][2])+ABC[i][j]

        if j==1:

            Happy[i][j]=max(Happy[i-1][0],Happy[i-1][2])+ABC[i][j]

        if j==2:

            Happy[i][j]=max(Happy[i-1][0],Happy[i-1][1])+ABC[i][j]

print((max(Happy[N-1])))
import numpy as np

N = int(eval(input()))
ABC = []
for i in range(N):
    ABC.append(list(map(int, input().split())))
dp = [[0, 0, 0] for i in range(N)]
dp[0] = ABC[0]
for i in range(1, N):
    for j in range(3):
        dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + ABC[i][j]
print((max(dp[N - 1])))

N = int(eval(input()))
ABC = []
for i in range(N):
    ABC.append(list(map(int, input().split())))
Happy = [[0, 0, 0] for i in range(N)]
Happy[0] = ABC[0]
for i in range(1, N):
    for j in range(3):
        if j == 0:
            Happy[i][j] = max(Happy[i - 1][1], Happy[i - 1][2]) + ABC[i][j]
        if j == 1:
            Happy[i][j] = max(Happy[i - 1][0], Happy[i - 1][2]) + ABC[i][j]
        if j == 2:
            Happy[i][j] = max(Happy[i - 1][0], Happy[i - 1][1]) + ABC[i][j]
print((max(Happy[N - 1])))

-import numpy as np - -dp = [[0, 0, 0] for i in range(N)] -dp[0] = ABC[0] +Happy = [[0, 0, 0] for i in range(N)] +Happy[0] = ABC[0] -        dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + ABC[i][j] -print((max(dp[N - 1]))) +        if j == 0: +            Happy[i][j] = max(Happy[i - 1][1], Happy[i - 1][2]) + ABC[i][j] +        if j == 1: +            Happy[i][j] = max(Happy[i - 1][0], Happy[i - 1][2]) + ABC[i][j] +        if j == 2: +            Happy[i][j] = max(Happy[i - 1][0], Happy[i - 1][1]) + ABC[i][j] +print((max(Happy[N - 1])))