n = int(eval(input()))

a = [list(map(int, input().split())) for i in range(n)]

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

for i in range(n):

    for j in range(3):

        for k in range(3):

            if j != k:

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

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

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

for i in range(1,n):

    aa,bb,cc = list(map(int,input().split()))

    aaa,bbb,ccc = a,b,c

    a = max(aa+bbb,aa+ccc)

    b = max(bb+ccc,bb+aaa)

    c = max(cc+aaa,cc+bbb)

print((max(a,b,c)))
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
dp = [[0 for i in range(3)] for j in range(n + 1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j])
print((max(dp[n])))

n = int(eval(input()))
a, b, c = list(map(int, input().split()))
for i in range(1, n):
    aa, bb, cc = list(map(int, input().split()))
    aaa, bbb, ccc = a, b, c
    a = max(aa + bbb, aa + ccc)
    b = max(bb + ccc, bb + aaa)
    c = max(cc + aaa, cc + bbb)
print((max(a, b, c)))

-a = [list(map(int, input().split())) for i in range(n)] -dp = [[0 for i in range(3)] for j in range(n + 1)] -for i in range(n): -    for j in range(3): -        for k in range(3): -            if j != k: -                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j]) -print((max(dp[n]))) +a, b, c = list(map(int, input().split())) +for i in range(1, n): +    aa, bb, cc = list(map(int, input().split())) +    aaa, bbb, ccc = a, b, c +    a = max(aa + bbb, aa + ccc) +    b = max(bb + ccc, bb + aaa) +    c = max(cc + aaa, cc + bbb) +print((max(a, b, c)))