N = int(eval(input()))

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



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





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

    for j in range(3):

        for k in range(3):

            if j != k:

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



print((max(dp[N][0], dp[N][1], dp[N][2])))



N = int(eval(input()))

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



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

    hapiness = list(map(int, input().split()))

    for j in range(3):

        for k in range(3):

            if j != k:

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



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

N = int(eval(input()))
dp = [[0 for i in range(3)] for j in range(N + 1)]
for i in range(1, N + 1):
    hapiness = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + hapiness[k])
print((max(dp[N][0], dp[N][1], dp[N][2])))

-l = [list(map(int, input().split())) for _ in range(N)] +    hapiness = list(map(int, input().split())) -                dp[i][j] = max(dp[i][j], dp[i - 1][k] + l[i - 1][k]) +                dp[i][j] = max(dp[i][j], dp[i - 1][k] + hapiness[k])