N = int(eval(input()))

vacation = []

for i in range(N):

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



activities = 3

schedules = [[None for _ in range(activities)] for _ in range(N)]

schedules[0] = vacation[0]



for i in range(1, N):

    for j in range(activities):

        schedules[i][j] = max(schedules[i - 1][(j + 1) % 3], schedules[i - 1][(j + 2) % 3]) + vacation[i][j]



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



felicidade = []



for x in range(n):

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



dp = []



dp.append([felicidade[0][0],felicidade[0][1],felicidade[0][2]])



for i in range(n-1):

    dp.append([0,0,0])





for dia in range(1,n):

    dp[dia][0] = felicidade[dia][0] + max(dp[dia-1][1], dp[dia-1][2])

    dp[dia][1] = felicidade[dia][1] + max(dp[dia-1][0],dp[dia-1][2])

    dp[dia][2] = felicidade[dia][2] + max(dp[dia-1][0], dp[dia-1][1])





print((max(dp[n-1])))

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

n = int(eval(input()))
felicidade = []
for x in range(n):
    felicidade.append(list(map(int, input().split())))
dp = []
dp.append([felicidade[0][0], felicidade[0][1], felicidade[0][2]])
for i in range(n - 1):
    dp.append([0, 0, 0])
for dia in range(1, n):
    dp[dia][0] = felicidade[dia][0] + max(dp[dia - 1][1], dp[dia - 1][2])
    dp[dia][1] = felicidade[dia][1] + max(dp[dia - 1][0], dp[dia - 1][2])
    dp[dia][2] = felicidade[dia][2] + max(dp[dia - 1][0], dp[dia - 1][1])
print((max(dp[n - 1])))

-N = int(eval(input())) -vacation = [] -for i in range(N): -    vacation.append(list(map(int, input().split()))) -activities = 3 -schedules = [[None for _ in range(activities)] for _ in range(N)] -schedules[0] = vacation[0] -for i in range(1, N): -    for j in range(activities): -        schedules[i][j] = ( -            max(schedules[i - 1][(j + 1) % 3], schedules[i - 1][(j + 2) % 3]) -            + vacation[i][j] -        ) -print((max(schedules[N - 1]))) +n = int(eval(input())) +felicidade = [] +for x in range(n): +    felicidade.append(list(map(int, input().split()))) +dp = [] +dp.append([felicidade[0][0], felicidade[0][1], felicidade[0][2]]) +for i in range(n - 1): +    dp.append([0, 0, 0]) +for dia in range(1, n): +    dp[dia][0] = felicidade[dia][0] + max(dp[dia - 1][1], dp[dia - 1][2]) +    dp[dia][1] = felicidade[dia][1] + max(dp[dia - 1][0], dp[dia - 1][2]) +    dp[dia][2] = felicidade[dia][2] + max(dp[dia - 1][0], dp[dia - 1][1]) +print((max(dp[n - 1])))