N=int(eval(input()))

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



for j in range(N):

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

    for i in range(3):

        if j==0:

            dp[i][j]=abc[i]

        else:

            dp[i][j]=max([dp[k][j-1]+abc[i] for k in range(3) if k!=i])

print((max([dp[i][N-1] for i in range(3)])))
N = int(eval(input()))



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

for i in range(1, N):

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

    newDP = [0] * 3

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

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

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



    dp = newDP[::]



ans = max(dp)

print(ans)

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

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

-dp = [[0 for i in range(N + 1)] for i in range(3)] -for j in range(N): -    abc = list(map(int, input().split())) -    for i in range(3): -        if j == 0: -            dp[i][j] = abc[i] -        else: -            dp[i][j] = max([dp[k][j - 1] + abc[i] for k in range(3) if k != i]) -print((max([dp[i][N - 1] for i in range(3)]))) +dp = list(map(int, input().split())) +for i in range(1, N): +    a, b, c = list(map(int, input().split())) +    newDP = [0] * 3 +    newDP[0] = max(dp[1], dp[2]) + a +    newDP[1] = max(dp[0], dp[2]) + b +    newDP[2] = max(dp[0], dp[1]) + c +    dp = newDP[::] +ans = max(dp) +print(ans)