N = int(eval(input()))

ABC = []

for _ in range(N):

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

        ABC.append((a,b,c))



dpA = [ABC[0][0]]*N

dpB = [ABC[0][1]]*N

dpC = [ABC[0][2]]*N



for i in range(1, N):

        dpA[i] = max(dpB[i-1] + ABC[i][0], dpC[i-1] + ABC[i][0])

        dpB[i] = max(dpA[i-1] + ABC[i][1], dpC[i-1] + ABC[i][1])

        dpC[i] = max(dpA[i-1] + ABC[i][2], dpB[i-1] + ABC[i][2])

print((max(dpA[N-1], dpB[N-1], dpC[N-1])))
N = int(eval(input()))

for i in range(N):

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

        if i == 0:

                preA = a

                preB = b

                preC = c

        else:

                A = max(preB + a, preC + a)

                B = max(preA + b, preC + b)

                C = max(preA + c, preB + c)

                preA = A

                preB = B

                preC = C

print((max(preA, preB, preC)))
N = int(eval(input()))
ABC = []
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    ABC.append((a, b, c))
dpA = [ABC[0][0]] * N
dpB = [ABC[0][1]] * N
dpC = [ABC[0][2]] * N
for i in range(1, N):
    dpA[i] = max(dpB[i - 1] + ABC[i][0], dpC[i - 1] + ABC[i][0])
    dpB[i] = max(dpA[i - 1] + ABC[i][1], dpC[i - 1] + ABC[i][1])
    dpC[i] = max(dpA[i - 1] + ABC[i][2], dpB[i - 1] + ABC[i][2])
print((max(dpA[N - 1], dpB[N - 1], dpC[N - 1])))

N = int(eval(input()))
for i in range(N):
    a, b, c = list(map(int, input().split()))
    if i == 0:
        preA = a
        preB = b
        preC = c
    else:
        A = max(preB + a, preC + a)
        B = max(preA + b, preC + b)
        C = max(preA + c, preB + c)
        preA = A
        preB = B
        preC = C
print((max(preA, preB, preC)))

-ABC = [] -for _ in range(N): +for i in range(N): -    ABC.append((a, b, c)) -dpA = [ABC[0][0]] * N -dpB = [ABC[0][1]] * N -dpC = [ABC[0][2]] * N -for i in range(1, N): -    dpA[i] = max(dpB[i - 1] + ABC[i][0], dpC[i - 1] + ABC[i][0]) -    dpB[i] = max(dpA[i - 1] + ABC[i][1], dpC[i - 1] + ABC[i][1]) -    dpC[i] = max(dpA[i - 1] + ABC[i][2], dpB[i - 1] + ABC[i][2]) -print((max(dpA[N - 1], dpB[N - 1], dpC[N - 1]))) +    if i == 0: +        preA = a +        preB = b +        preC = c +    else: +        A = max(preB + a, preC + a) +        B = max(preA + b, preC + b) +        C = max(preA + c, preB + c) +        preA = A +        preB = B +        preC = C +print((max(preA, preB, preC)))