import sys

sys.setrecursionlimit(1000000)



N = int(eval(input()))

a = [[0]*3 for i in range(N)]



for i in range(N):

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



def f(n, i):

  if n ==0:

    return a[0][i]

  i1 = (i+1) % 3

  i2 = (i+2) % 3

  if F[n][i]:

    return F[n][i]

  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 

  return F[n][i]  



F =[[None]*3 for _ in range(N)]



print((max(f(N-1, 0), f(N-1,1), f(N-1,2))))

N = int(eval(input()))

a = [[0]*3 for i in range(N)]



for i in range(N):

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



def summerVacation(n, i):

  if n ==0:

    dp[n][i] = a[n][i]

    return

  i1 = (i+1) % 3

  i2 = (i+2) % 3  

  dp[n][i] = max( dp[n-1][i1], dp[n-1][i2] ) + a[n][i]  

  

dp =[[None]*3 for _ in range(N)]

for n in range(N):

  for i in range(3):

    summerVacation(n, i)

    

print(( max( dp[N-1][0], dp[N-1][1], dp[N-1][2] )))



  
import sys

sys.setrecursionlimit(1000000)
N = int(eval(input()))
a = [[0] * 3 for i in range(N)]
for i in range(N):
    a[i] = [int(i) for i in input().split()]


def f(n, i):
    if n == 0:
        return a[0][i]
    i1 = (i + 1) % 3
    i2 = (i + 2) % 3
    if F[n][i]:
        return F[n][i]
    F[n][i] = max(f(n - 1, i1), f(n - 1, i2)) + a[n][i]
    return F[n][i]


F = [[None] * 3 for _ in range(N)]
print((max(f(N - 1, 0), f(N - 1, 1), f(N - 1, 2))))

N = int(eval(input()))
a = [[0] * 3 for i in range(N)]
for i in range(N):
    a[i] = [int(i) for i in input().split()]


def summerVacation(n, i):
    if n == 0:
        dp[n][i] = a[n][i]
        return
    i1 = (i + 1) % 3
    i2 = (i + 2) % 3
    dp[n][i] = max(dp[n - 1][i1], dp[n - 1][i2]) + a[n][i]


dp = [[None] * 3 for _ in range(N)]
for n in range(N):
    for i in range(3):
        summerVacation(n, i)
print((max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2])))

-import sys - -sys.setrecursionlimit(1000000) -def f(n, i): +def summerVacation(n, i): -        return a[0][i] +        dp[n][i] = a[n][i] +        return -    if F[n][i]: -        return F[n][i] -    F[n][i] = max(f(n - 1, i1), f(n - 1, i2)) + a[n][i] -    return F[n][i] +    dp[n][i] = max(dp[n - 1][i1], dp[n - 1][i2]) + a[n][i] -F = [[None] * 3 for _ in range(N)] -print((max(f(N - 1, 0), f(N - 1, 1), f(N - 1, 2)))) +dp = [[None] * 3 for _ in range(N)] +for n in range(N): +    for i in range(3): +        summerVacation(n, i) +print((max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2])))