N = int(eval(input()))

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

for i in range(N):

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

    for j in range(3):

        a[i][j] = t[j]



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



for i in range(N):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

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

#print(dp)





answer = 0

for j in range(3):

    answer = max(answer, dp[N][j])



print(answer)
INF = float('inf')

MAX_N = 10**5



N = int(eval(input()))

a,b,c = [0]*N, [0]*N, [0]*N

for i in range(N):

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



# dp table

# dp[i][j] := 状態jにおけるi日目に得る幸福度の総和の最大値

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



dp[0][0],dp[0][1],dp[0][2] = a[0],b[0],c[0]



for i in range(1,N):

    for j in range(3):

        if j==0:

            dp[i][j] = max(dp[i-1][j+1]+a[i],dp[i-1][j+2]+a[i])

        if j==1:

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

        if j==2:

            dp[i][j] = max(dp[i-1][j-2]+c[i],dp[i-1][j-1]+c[i])

print((max(dp[N-1])))
N = int(eval(input()))
a = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    t = list(map(int, input().split()))
    for j in range(3):
        a[i][j] = t[j]
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
# print(dp)
answer = 0
for j in range(3):
    answer = max(answer, dp[N][j])
print(answer)

INF = float("inf")
MAX_N = 10**5
N = int(eval(input()))
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
    a[i], b[i], c[i] = list(map(int, input().split()))
# dp table
# dp[i][j] := 状態jにおけるi日目に得る幸福度の総和の最大値
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = a[0], b[0], c[0]
for i in range(1, N):
    for j in range(3):
        if j == 0:
            dp[i][j] = max(dp[i - 1][j + 1] + a[i], dp[i - 1][j + 2] + a[i])
        if j == 1:
            dp[i][j] = max(dp[i - 1][j - 1] + b[i], dp[i - 1][j + 1] + b[i])
        if j == 2:
            dp[i][j] = max(dp[i - 1][j - 2] + c[i], dp[i - 1][j - 1] + c[i])
print((max(dp[N - 1])))

+INF = float("inf") +MAX_N = 10**5 -a = [[0 for _ in range(3)] for _ in range(N)] +a, b, c = [0] * N, [0] * N, [0] * N -    t = list(map(int, input().split())) +    a[i], b[i], c[i] = list(map(int, input().split())) +# dp table +# dp[i][j] := 状態jにおけるi日目に得る幸福度の総和の最大値 +dp = [[0] * 3 for _ in range(N)] +dp[0][0], dp[0][1], dp[0][2] = a[0], b[0], c[0] +for i in range(1, N): -        a[i][j] = t[j] -dp = [[0 for _ in range(3)] for _ in range(N + 1)] -for i in range(N): -    for j in range(3): -        for k in range(3): -            if j == k: -                continue -            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]) -# print(dp) -answer = 0 -for j in range(3): -    answer = max(answer, dp[N][j]) -print(answer) +        if j == 0: +            dp[i][j] = max(dp[i - 1][j + 1] + a[i], dp[i - 1][j + 2] + a[i]) +        if j == 1: +            dp[i][j] = max(dp[i - 1][j - 1] + b[i], dp[i - 1][j + 1] + b[i]) +        if j == 2: +            dp[i][j] = max(dp[i - 1][j - 2] + c[i], dp[i - 1][j - 1] + c[i]) +print((max(dp[N - 1])))