N = int(eval(input()))

A, B, C = [0]*N, [0]*N, [0]*N 

for i in range(N):

    A[i], B[i], C[i] = [int(j) for j in input().split()]



ABC = [A, B, C]

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



for i in range(N):

    for j in range(3):

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



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

data = [[] for _ in range(N)]

for i in range(N):

    data[i] = [int(i) for i in input().split()]



#%%

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

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

    for j in range(3):

        temp = max(dp[i - 1][j - 1], dp[i - 1][j - 2])

        dp[i][j]= data[i - 1][j] + temp



ans = 0

for i in range(3):

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



print(ans)

N = int(eval(input()))
A, B, C = [0] * N, [0] * N, [0] * N
for i in range(N):
    A[i], B[i], C[i] = [int(j) for j in input().split()]
ABC = [A, B, C]
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][j - 1], dp[i][j - 2]) + ABC[j][i]
print((max(dp[-1])))

N = int(eval(input()))
data = [[] for _ in range(N)]
for i in range(N):
    data[i] = [int(i) for i in input().split()]
#%%
dp = [[0] * 3 for i in range(N + 1)]
for i in range(1, N + 1):
    for j in range(3):
        temp = max(dp[i - 1][j - 1], dp[i - 1][j - 2])
        dp[i][j] = data[i - 1][j] + temp
ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])
print(ans)

-A, B, C = [0] * N, [0] * N, [0] * N +data = [[] for _ in range(N)] -    A[i], B[i], C[i] = [int(j) for j in input().split()] -ABC = [A, B, C] -dp = [[0] * 3 for _ in range(N + 1)] -for i in range(N): +    data[i] = [int(i) for i in input().split()] +#%% +dp = [[0] * 3 for i in range(N + 1)] +for i in range(1, N + 1): -        dp[i + 1][j] = max(dp[i][j - 1], dp[i][j - 2]) + ABC[j][i] -print((max(dp[-1]))) +        temp = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) +        dp[i][j] = data[i - 1][j] + temp +ans = 0 +for i in range(3): +    ans = max(ans, dp[N][i]) +print(ans)