import numpy as np



n = int(eval(input()))

X = np.array([input().split() for _ in range(n)], np.int64)

dp = np.zeros((n + 1, 3), np.int64)

dp[0, 0] = dp[0, 1] = dp[0, 2] = 0

for i in range(n):

    for j in range(3):

        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)

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

x, y, z = 0, 0, 0

for _ in range(N):

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

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

print((max(x, y, z)))
import numpy as np

n = int(eval(input()))
X = np.array([input().split() for _ in range(n)], np.int64)
dp = np.zeros((n + 1, 3), np.int64)
dp[0, 0] = dp[0, 1] = dp[0, 2] = 0
for i in range(n):
    for j in range(3):
        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)
print((max(dp[n])))

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

-import numpy as np - -n = int(eval(input())) -X = np.array([input().split() for _ in range(n)], np.int64) -dp = np.zeros((n + 1, 3), np.int64) -dp[0, 0] = dp[0, 1] = dp[0, 2] = 0 -for i in range(n): -    for j in range(3): -        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k) -print((max(dp[n]))) +N = int(eval(input())) +x, y, z = 0, 0, 0 +for _ in range(N): +    a, b, c = list(map(int, input().split())) +    x, y, z = max(y, z) + a, max(z, x) + b, max(x, y) + c +print((max(x, y, z)))