n = int(eval(input()))

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

ls  = [[1,2],[0,2],[0,1]]

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

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

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

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

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

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

N = int(eval(input()))

ls = [[0 for i in range(3)] for i in range(N)]

for i in range(N):

    ls[i] = list(map(int,input().split()))

# dp[i][j] -> i-1日目にjの仕事をしたときの i 日目の幸福度の総和

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

for i in range(3):

    dp[0][i] = ls[0][i]

for i in range(1,N):

    for j in range(3):

        w = [0,1,2]

        w.remove(j)

        x,y = w[0],w[1]

        dp[i][j] = max(dp[i-1][x],dp[i-1][y]) + ls[i][j]

            

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

n = int(eval(input()))
dp = [[0 for _ in range(3)] for _ in range(n + 1)]
ls = [[1, 2], [0, 2], [0, 1]]
for i in range(1, n + 1):
    day = list(map(int, input().split()))
    dp[i][0] = day[0] + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = day[1] + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = day[2] + max(dp[i - 1][0], dp[i - 1][1])
print((max(dp[n])))

N = int(eval(input()))
ls = [[0 for i in range(3)] for i in range(N)]
for i in range(N):
    ls[i] = list(map(int, input().split()))
# dp[i][j] -> i-1日目にjの仕事をしたときの i 日目の幸福度の総和
dp = [[0 for i in range(3)] for i in range(N)]
for i in range(3):
    dp[0][i] = ls[0][i]
for i in range(1, N):
    for j in range(3):
        w = [0, 1, 2]
        w.remove(j)
        x, y = w[0], w[1]
        dp[i][j] = max(dp[i - 1][x], dp[i - 1][y]) + ls[i][j]
print((max(dp[N - 1])))

-n = int(eval(input())) -dp = [[0 for _ in range(3)] for _ in range(n + 1)] -ls = [[1, 2], [0, 2], [0, 1]] -for i in range(1, n + 1): -    day = list(map(int, input().split())) -    dp[i][0] = day[0] + max(dp[i - 1][1], dp[i - 1][2]) -    dp[i][1] = day[1] + max(dp[i - 1][0], dp[i - 1][2]) -    dp[i][2] = day[2] + max(dp[i - 1][0], dp[i - 1][1]) -print((max(dp[n]))) +N = int(eval(input())) +ls = [[0 for i in range(3)] for i in range(N)] +for i in range(N): +    ls[i] = list(map(int, input().split())) +# dp[i][j] -> i-1日目にjの仕事をしたときの i 日目の幸福度の総和 +dp = [[0 for i in range(3)] for i in range(N)] +for i in range(3): +    dp[0][i] = ls[0][i] +for i in range(1, N): +    for j in range(3): +        w = [0, 1, 2] +        w.remove(j) +        x, y = w[0], w[1] +        dp[i][j] = max(dp[i - 1][x], dp[i - 1][y]) + ls[i][j] +print((max(dp[N - 1])))