n = int(eval(input()))

e = tuple(tuple(map(int, input().split())) for _ in range(n))



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



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

    for j in range(3):

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

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

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



print((max(dp[n])))

n = int(eval(input()))

v = tuple(tuple(map(int, input().split())) for _ in range(n))

e = tuple(zip(*v))

# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度

# print(e)



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

# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度



# もらう

for i in range(n):

    for j in range(3):

        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]

print((max(dp[n])))

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

n = int(eval(input()))
v = tuple(tuple(map(int, input().split())) for _ in range(n))
e = tuple(zip(*v))
# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度
# print(e)
dp = tuple([0] * 3 for _ in range(n + 1))
# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度
# もらう
for i in range(n):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]
print((max(dp[n])))

-e = tuple(tuple(map(int, input().split())) for _ in range(n)) -dp = [[0] * 3 for _ in range(n + 1)] -for i in range(1, n + 1): +v = tuple(tuple(map(int, input().split())) for _ in range(n)) +e = tuple(zip(*v)) +# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度 +# print(e) +dp = tuple([0] * 3 for _ in range(n + 1)) +# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度 +# もらう +for i in range(n): -        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + e[i - 1][0] -        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + e[i - 1][1] -        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + e[i - 1][2] +        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]