N = int(eval(input()))

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



# dp[i][j] i日目にjを選んだ場合の幸福度

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



for i, a in enumerate(A):

  for j, h in enumerate(a):

    dp[i+1][j] = max(dp[i][(1+j)%3], dp[i][(2+j)%3]) + h

    

print((max(dp[N])))
N, *A = list(map(int, open(0).read().split()))

*A, = list(zip(*[iter(A)]*3))



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

for i, (a, b, c) in enumerate(A):

    if i == 0:

        dp[i] = [a, b, c]

        continue



    da, db, dc = dp[i-1]

    dp[i][0] = max(dp[i][0], max(db, dc)+a)

    dp[i][1] = max(dp[i][1], max(dc, da)+b)

    dp[i][2] = max(dp[i][2], max(da, db)+c)



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

N = int(eval(input()))
A = [tuple(map(int, input().split())) for _ in range(N)]
# dp[i][j] i日目にjを選んだ場合の幸福度
dp = [[0] * 3 for _ in range(N + 1)]
for i, a in enumerate(A):
    for j, h in enumerate(a):
        dp[i + 1][j] = max(dp[i][(1 + j) % 3], dp[i][(2 + j) % 3]) + h
print((max(dp[N])))

N, *A = list(map(int, open(0).read().split()))
(*A,) = list(zip(*[iter(A)] * 3))
dp = [[0] * 3 for _ in range(N)]
for i, (a, b, c) in enumerate(A):
    if i == 0:
        dp[i] = [a, b, c]
        continue
    da, db, dc = dp[i - 1]
    dp[i][0] = max(dp[i][0], max(db, dc) + a)
    dp[i][1] = max(dp[i][1], max(dc, da) + b)
    dp[i][2] = max(dp[i][2], max(da, db) + c)
print((max(dp[-1])))

-N = int(eval(input())) -A = [tuple(map(int, input().split())) for _ in range(N)] -# dp[i][j] i日目にjを選んだ場合の幸福度 -dp = [[0] * 3 for _ in range(N + 1)] -for i, a in enumerate(A): -    for j, h in enumerate(a): -        dp[i + 1][j] = max(dp[i][(1 + j) % 3], dp[i][(2 + j) % 3]) + h -print((max(dp[N]))) +N, *A = list(map(int, open(0).read().split())) +(*A,) = list(zip(*[iter(A)] * 3)) +dp = [[0] * 3 for _ in range(N)] +for i, (a, b, c) in enumerate(A): +    if i == 0: +        dp[i] = [a, b, c] +        continue +    da, db, dc = dp[i - 1] +    dp[i][0] = max(dp[i][0], max(db, dc) + a) +    dp[i][1] = max(dp[i][1], max(dc, da) + b) +    dp[i][2] = max(dp[i][2], max(da, db) + c) +print((max(dp[-1])))