n = int(eval(input()))

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



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

for i in range(1, n):

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

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

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

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

    

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

dp = [0] * 3



for i in range(n):

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

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

          

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

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

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