N = int(eval(input()))



abc = [list([int(x) for x in input().split()]) for _ in range(N)]



happy = [[0] * 3 for _ in range(N)]

for i in range(3):

	happy[0][i] = abc[0][i]



for i in range(1, N):

	happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0]

	happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1]

	happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2]



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



l = [0] * 3

for i in range(N):

    a = [int(x) for x in input().split()]

    c = [a[0] + max(l[1], l[2]), a[1] + max(l[2], l[0]), a[2] + max(l[0], l[1])]

    l = c

print((max(l)))
N = int(eval(input()))
abc = [list([int(x) for x in input().split()]) for _ in range(N)]
happy = [[0] * 3 for _ in range(N)]
for i in range(3):
    happy[0][i] = abc[0][i]
for i in range(1, N):
    happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0]
    happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1]
    happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2]
print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2])))

N = int(eval(input()))
l = [0] * 3
for i in range(N):
    a = [int(x) for x in input().split()]
    c = [a[0] + max(l[1], l[2]), a[1] + max(l[2], l[0]), a[2] + max(l[0], l[1])]
    l = c
print((max(l)))

-abc = [list([int(x) for x in input().split()]) for _ in range(N)] -happy = [[0] * 3 for _ in range(N)] -for i in range(3): -    happy[0][i] = abc[0][i] -for i in range(1, N): -    happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0] -    happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1] -    happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2] -print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2]))) +l = [0] * 3 +for i in range(N): +    a = [int(x) for x in input().split()] +    c = [a[0] + max(l[1], l[2]), a[1] + max(l[2], l[0]), a[2] + max(l[0], l[1])] +    l = c +print((max(l)))