N = int(eval(input()))

Y = []

for _ in range(N):

    Y.append(list(map(int, input().split())))  # Y = [[3, 9, 7], [10, 3, 2]]

dp = [[0] * 3 for _ in range(N)]  # 初期化

dp[0] = Y[0]  # 初期化



# A, B, C の3パターン以外にも対応

for i in range(N-1):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

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

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

A = [0] * N

B = [0] * N

C = [0] * N

for i in range(N):

    A[i], B[i], C[i] = list(map(int, input().split()))

dp = [[0] * 3 for _ in range(N)]  # 初期化　[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4

dp[0] = [A[0], B[0], C[0]]



for i in range(N-1):

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

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

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

print((max(dp[N-1])))
N = int(eval(input()))
Y = []
for _ in range(N):
    Y.append(list(map(int, input().split())))  # Y = [[3, 9, 7], [10, 3, 2]]
dp = [[0] * 3 for _ in range(N)]  # 初期化
dp[0] = Y[0]  # 初期化
# A, B, C の3パターン以外にも対応
for i in range(N - 1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + Y[i + 1][j])
print((max(dp[N - 1])))

N = int(eval(input()))
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
    A[i], B[i], C[i] = list(map(int, input().split()))
dp = [
    [0] * 3 for _ in range(N)
]  # 初期化　[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4
dp[0] = [A[0], B[0], C[0]]
for i in range(N - 1):
    dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1])
    dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1])
    dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1])
print((max(dp[N - 1])))

-Y = [] -for _ in range(N): -    Y.append(list(map(int, input().split())))  # Y = [[3, 9, 7], [10, 3, 2]] -dp = [[0] * 3 for _ in range(N)]  # 初期化 -dp[0] = Y[0]  # 初期化 -# A, B, C の3パターン以外にも対応 +A = [0] * N +B = [0] * N +C = [0] * N +for i in range(N): +    A[i], B[i], C[i] = list(map(int, input().split())) +dp = [ +    [0] * 3 for _ in range(N) +]  # 初期化　[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4 +dp[0] = [A[0], B[0], C[0]] -    for j in range(3): -        for k in range(3): -            if j == k: -                continue -            dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + Y[i + 1][j]) +    dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1]) +    dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1]) +    dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1])