N = int(eval(input()))

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



dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))

for i in range(1,N):

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

  for j,k,l in ((0,1,2), (1,0,2), (2, 0, 1)):

    dp[i][j] = abc[j] + max(dp[i-1][k], dp[i-1][l])



print((max(dp[N-1])))
N = int(eval(input()))



x, y, z = list(map(int, input().split()))

for _ in range(N-1):

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

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



print((max(x,y,z)))
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))
for i in range(1, N):
    abc = list(map(int, input().split()))
    for j, k, l in ((0, 1, 2), (1, 0, 2), (2, 0, 1)):
        dp[i][j] = abc[j] + max(dp[i - 1][k], dp[i - 1][l])
print((max(dp[N - 1])))

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

-dp = [[0] * 3 for _ in range(N)] -dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split())) -for i in range(1, N): -    abc = list(map(int, input().split())) -    for j, k, l in ((0, 1, 2), (1, 0, 2), (2, 0, 1)): -        dp[i][j] = abc[j] + max(dp[i - 1][k], dp[i - 1][l]) -print((max(dp[N - 1]))) +x, y, z = list(map(int, input().split())) +for _ in range(N - 1): +    a, b, c = list(map(int, input().split())) +    x, y, z = a + max(y, z), b + max(x, z), c + max(x, y) +print((max(x, y, z)))