n=int(eval(input()))

a=[0]*n

b=[0]*n

c=[0]*n

for i in range(n):

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



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

for i in range(1,n+1):

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

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

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



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

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

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

dp[0]=l[0]

for i in range(n-1):

    for j in range(3):

        dp[i+1][j]=max(dp[i][(j+1)%3],dp[i][(j+2)%3])+l[i+1][j]

print((max(dp[n-1])))
n = int(eval(input()))
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
    a[i], b[i], c[i] = list(map(int, input().split()))
dp = [[0, 0, 0] for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1]
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i - 1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i - 1]
print((max(dp[n])))

n = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = l[0]
for i in range(n - 1):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + l[i + 1][j]
print((max(dp[n - 1])))

-a = [0] * n -b = [0] * n -c = [0] * n -for i in range(n): -    a[i], b[i], c[i] = list(map(int, input().split())) -dp = [[0, 0, 0] for _ in range(n + 1)] -for i in range(1, n + 1): -    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1] -    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i - 1] -    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i - 1] -print((max(dp[n]))) +l = [list(map(int, input().split())) for _ in range(n)] +dp = [[0] * 3 for _ in range(n)] +dp[0] = l[0] +for i in range(n - 1): +    for j in range(3): +        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + l[i + 1][j] +print((max(dp[n - 1])))