n = int(eval(input()))

Act = [list(map(int,input().split())) for i in range(n)]



dp = [[0,0,0] for i in range(n)]

dp[0] = [Act[0][j] for j in range(3)]



for i in range(1,n):

  for j in range(3):

    s = 0 

    for k in range(3):

      s = max(s,(dp[i-1][k]+Act[i][j])*int(j!=k))

    dp[i][j] = s



print((max(dp[n-1][0],dp[n-1][1],dp[n-1][2])))
N = int(eval(input()))



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



for i in range(1, N + 1):

    a = tuple(map(int, input().split()))

    for j in range(3):

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



print((max(dp[N])))
n = int(eval(input()))
Act = [list(map(int, input().split())) for i in range(n)]
dp = [[0, 0, 0] for i in range(n)]
dp[0] = [Act[0][j] for j in range(3)]
for i in range(1, n):
    for j in range(3):
        s = 0
        for k in range(3):
            s = max(s, (dp[i - 1][k] + Act[i][j]) * int(j != k))
        dp[i][j] = s
print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))

N = int(eval(input()))
dp = [[0, 0, 0] for _ in range(N + 1)]
for i in range(1, N + 1):
    a = tuple(map(int, input().split()))
    for j in range(3):
        dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j])
print((max(dp[N])))

-n = int(eval(input())) -Act = [list(map(int, input().split())) for i in range(n)] -dp = [[0, 0, 0] for i in range(n)] -dp[0] = [Act[0][j] for j in range(3)] -for i in range(1, n): +N = int(eval(input())) +dp = [[0, 0, 0] for _ in range(N + 1)] +for i in range(1, N + 1): +    a = tuple(map(int, input().split())) -        s = 0 -        for k in range(3): -            s = max(s, (dp[i - 1][k] + Act[i][j]) * int(j != k)) -        dp[i][j] = s -print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))) +        dp[i][j] = max(dp[i - 1][j - 1] + a[j], dp[i - 1][j - 2] + a[j]) +print((max(dp[N])))