N = int(eval(input()))

a_list = [[0 for _ in range(3)] for _ in range(N)]



for i in range(N):

    a, b, c = list(map(int, input().split()))

    a_list[i][0] = a

    a_list[i][1] = b

    a_list[i][2] = c



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



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

    for j in range(3):

        for k in range(3):

            if i == 1:

                dp[i][j] = a_list[i - 1][k]

            if j == k:

                continue

            else:

                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])

print((max(dp[N])))

N = int(eval(input()))

abc = []

for i in range(N):

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



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



for i in range(N):

    a, b, c = abc[i]

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

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

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





print((max(dp[N])))

N = int(eval(input()))
a_list = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    a, b, c = list(map(int, input().split()))
    a_list[i][0] = a
    a_list[i][1] = b
    a_list[i][2] = c
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if i == 1:
                dp[i][j] = a_list[i - 1][k]
            if j == k:
                continue
            else:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])
print((max(dp[N])))

N = int(eval(input()))
abc = []
for i in range(N):
    abc.append(tuple(map(int, input().split())))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
    a, b, c = abc[i]
    dp[i + 1][0] += max(dp[i][1] + a, dp[i][2] + a)
    dp[i + 1][1] += max(dp[i][0] + b, dp[i][2] + b)
    dp[i + 1][2] += max(dp[i][0] + c, dp[i][1] + c)
print((max(dp[N])))

-a_list = [[0 for _ in range(3)] for _ in range(N)] +abc = [] -    a, b, c = list(map(int, input().split())) -    a_list[i][0] = a -    a_list[i][1] = b -    a_list[i][2] = c -dp = [[0 for _ in range(3)] for _ in range(N + 1)] -for i in range(1, N + 1): -    for j in range(3): -        for k in range(3): -            if i == 1: -                dp[i][j] = a_list[i - 1][k] -            if j == k: -                continue -            else: -                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j]) +    abc.append(tuple(map(int, input().split()))) +dp = [[0] * 3 for _ in range(N + 1)] +for i in range(N): +    a, b, c = abc[i] +    dp[i + 1][0] += max(dp[i][1] + a, dp[i][2] + a) +    dp[i + 1][1] += max(dp[i][0] + b, dp[i][2] + b) +    dp[i + 1][2] += max(dp[i][0] + c, dp[i][1] + c)