N = int(eval(input()))

L = list(list(map(int,input().split())) for i in range(N))

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



for i in range(N) :

    dp[i+1][0] = max(dp[i][1], dp[i][2]) + L[i][0]

    dp[i+1][1] = max(dp[i][2], dp[i][0]) + L[i][1]

    dp[i+1][2] = max(dp[i][0], dp[i][1]) + L[i][2]



ans = max(dp[N][0], dp[N][1], dp[N][2])



print(ans)

N = int(eval(input()))

L = [list(map(int,input().split())) for i in range(N)]



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

dp[0] = L[0]



for i in range(1,N) :

    dp[i][0] = max(dp[i-1][1] + L[i][0],dp[i-1][2] + L[i][0])

    dp[i][1] = max(dp[i-1][2] + L[i][1],dp[i-1][0] + L[i][1])

    dp[i][2] = max(dp[i-1][0] + L[i][2],dp[i-1][1] + L[i][2])



ans = max(dp[N-1])



print(ans)

N = int(eval(input()))
L = list(list(map(int, input().split())) for i in range(N))
dp = [[0, 0, 0] for i in range(N + 1)]
for i in range(N):
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + L[i][0]
    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + L[i][1]
    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + L[i][2]
ans = max(dp[N][0], dp[N][1], dp[N][2])
print(ans)

N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0, 0, 0] for i in range(N)]
dp[0] = L[0]
for i in range(1, N):
    dp[i][0] = max(dp[i - 1][1] + L[i][0], dp[i - 1][2] + L[i][0])
    dp[i][1] = max(dp[i - 1][2] + L[i][1], dp[i - 1][0] + L[i][1])
    dp[i][2] = max(dp[i - 1][0] + L[i][2], dp[i - 1][1] + L[i][2])
ans = max(dp[N - 1])
print(ans)

-L = list(list(map(int, input().split())) for i in range(N)) -dp = [[0, 0, 0] for i in range(N + 1)] -for i in range(N): -    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + L[i][0] -    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + L[i][1] -    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + L[i][2] -ans = max(dp[N][0], dp[N][1], dp[N][2]) +L = [list(map(int, input().split())) for i in range(N)] +dp = [[0, 0, 0] for i in range(N)] +dp[0] = L[0] +for i in range(1, N): +    dp[i][0] = max(dp[i - 1][1] + L[i][0], dp[i - 1][2] + L[i][0]) +    dp[i][1] = max(dp[i - 1][2] + L[i][1], dp[i - 1][0] + L[i][1]) +    dp[i][2] = max(dp[i - 1][0] + L[i][2], dp[i - 1][1] + L[i][2]) +ans = max(dp[N - 1])