n = int(eval(input()))

a = [0] * n

for x in range(n):

    a[x] = list(map(int, input().split()))

# print(a)

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

# print(dp)

for i in range(n):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

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

# print(dp)

print((max(dp[n])))
MAX_N = 10 ** 5 + 10

N = int(eval(input()))

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



arr = [0] * MAX_N

for i in range(N):

    arr[i] = list(map(int, input().split()))

for i in range(N):

    for j in range(3):

        for k in range(3):

            if j == k:

                continue

            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + arr[i][k])

print((max(dp[N])))
n = int(eval(input()))
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))
# print(a)
dp = [[0 for _ in range(3)] for _ in range(n + 1)]
# print(dp)
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
# print(dp)
print((max(dp[n])))

MAX_N = 10**5 + 10
N = int(eval(input()))
dp = [[0] * 3 for _ in range(MAX_N)]
arr = [0] * MAX_N
for i in range(N):
    arr[i] = list(map(int, input().split()))
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + arr[i][k])
print((max(dp[N])))

-n = int(eval(input())) -a = [0] * n -for x in range(n): -    a[x] = list(map(int, input().split())) -# print(a) -dp = [[0 for _ in range(3)] for _ in range(n + 1)] -# print(dp) -for i in range(n): +MAX_N = 10**5 + 10 +N = int(eval(input())) +dp = [[0] * 3 for _ in range(MAX_N)] +arr = [0] * MAX_N +for i in range(N): +    arr[i] = list(map(int, input().split())) +for i in range(N): -            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]) -# print(dp) -print((max(dp[n]))) +            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + arr[i][k]) +print((max(dp[N])))