N = int(eval(input()))

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



dp = [[0]*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((max(dp[N])))
N = int(eval(input()))

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



x = y = z = 0

for a,b,c in A:

  x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c

print((max(x,y,z)))
N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 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((max(dp[N])))

N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
x = y = z = 0
for a, b, c in A:
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
print((max(x, y, z)))

-dp = [[0] * 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((max(dp[N]))) +x = y = z = 0 +for a, b, c in A: +    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c +print((max(x, y, z)))