n=int(eval(input()))

abc=[[int(i) for i in input().split()] for j in range(n)] 

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



for i in range(1,n):

    for j in range(3):

        for k in range(3):

            if j!=k:

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

    dp[0][0]=dp[1][0]

    dp[0][1]=dp[1][1]

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

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

abc=[[int(i) for i in input().split()] for j in range(n)]

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



for i in range(3):

    dp[1][i]=abc[0][i]

    

for i in range(1,n):

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

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

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

    

print((max(dp[-1])))

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

n = int(eval(input()))
abc = [[int(i) for i in input().split()] for j in range(n)]
dp = [[0 for i in range(3)] for j in range(n + 1)]
for i in range(3):
    dp[1][i] = abc[0][i]
for i in range(1, n):
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + abc[i][0]
    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + abc[i][1]
    dp[i + 1][2] = max(dp[i][1], dp[i][0]) + abc[i][2]
print((max(dp[-1])))

-dp = [[abc[0][0], abc[0][1], abc[0][2]], [abc[0][0], abc[0][1], abc[0][2]]] +dp = [[0 for i in range(3)] for j in range(n + 1)] +for i in range(3): +    dp[1][i] = abc[0][i] -    for j in range(3): -        for k in range(3): -            if j != k: -                dp[1][k] = max(dp[1][k], dp[0][j] + abc[i][k]) -    dp[0][0] = dp[1][0] -    dp[0][1] = dp[1][1] -    dp[0][2] = dp[1][2] -print((max(dp[1]))) +    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + abc[i][0] +    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + abc[i][1] +    dp[i + 1][2] = max(dp[i][1], dp[i][0]) + abc[i][2] +print((max(dp[-1])))