CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))

A, B, C = 0, 0, 0
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    A, B, C = max(B, C) + a, max(C, A) + b, max(A, B) + c
ans = max(A, B, C)

print(ans)

# Optimized solution
import sys
input=sys.stdin.readline


def solve():
  N = int(eval(input()))

  A, B, C = 0, 0, 0
  for _ in range(N):
      a, b, c = list(map(int, input().split()))
      A, B, C = max(B, C) + a, max(C, A) + b, max(A, B) + c
  return max(A, B, C)
 
if __name__ == "__main__":
	print((solve()))
# Original solution
def run():
  N = int(eval(input()))
  abc_li = [[int(i) for i in input().split()] for n in range(N)]
  dp = [0] * N
  dp[0] = [(abc_li[0][k], k) for k in range(3)]
  for n in range(1, N):
    len_dp = len(dp[n-1])
    dp[n] = [(0, 0) for _ in range(len_dp)]
    for k in range(len_dp):
      value, pre_abc = dp[n-1][k] 
      for abc, abc_value in enumerate(abc_li[n]):
        if pre_abc == abc: continue
        if dp[n][k][0] == (value + abc_value):
          dp[n].append((value + abc_value, abc))
          continue
        dp[n][k] = max([dp[n][k], (value + abc_value, abc)],
                      key=lambda x:x[0])
    dp[n] = list(set(dp[n]))
  print((max(dp[-1])[0]))
  
if __name__ == '__main__':
  run()

# Optimized solution
def run():
  N = int(eval(input()))
  abc_li = [[int(i) for i in input().split()] for n in range(N)]
  dp = [[0]*3 for n in range(N)]
  dp[0] = abc_li[0]
  for n in range(1, N):
    for next_abc in range(3):
      for pre_abc in range(3):
        if pre_abc == next_abc: continue
        dp[n][next_abc] = max(dp[n][next_abc], dp[n-1][pre_abc]+abc_li[n][next_abc])
  print((max(dp[N-1])))
  
if __name__ == '__main__':
  run()
# Original solution
n=int(eval(input()))
dp=[[0]*(n) for _ in range(3)]
l=[]
for i in range(n):
    a,b,c=list(map(int,input().split()))
    l.append([a,b,c])
dp[0][0],dp[1][0],dp[2][0]=l[0][0],l[0][1],l[0][2]
for i in range(0,n-1):
    dp[0][i+1]=max(dp[1][i]+l[i+1][0],dp[2][i]+l[i+1][0])
    dp[1][i+1]=max(dp[0][i]+l[i+1][1],dp[2][i]+l[i+1][1])
    dp[2][i+1]=max(dp[0][i]+l[i+1][2],dp[1][i]+l[i+1][2])
print((max([dp[0][n-1],dp[1][n-1],dp[2][n-1]])))


# Optimized solution
import sys
input=sys.stdin.readline

n=int(eval(input()))
dp=[[0]*3  for _ in range(n)]
a,b,c=list(map(int,input().split()))
dp[0]=[a,b,c]
for i in range(1,n):
    a,b,c=list(map(int,input().split()))
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print((max(dp[n-1])))
# Original solution
import sys
sys.setrecursionlimit(1000000)
def maxcost(li,n,i,strt,dp):
    if i==(n-1):
        return li[i][strt]
    mx=-sys.maxsize
    for l in range(3):
        if l!=strt:
            if dp[i+1][l]==-1:
                cost=maxcost(li,n,i+1,l,dp)
                dp[i+1][l]=cost
            else:
                cost=dp[i+1][l]
            mx=max(mx,cost+li[i][strt])
    return mx


n=int(eval(input()))
li=[]
for i in range(n):
    temp=[int(x) for x in input().split()]
    li.append(temp)
dp=[[-1 for j in range(3)] for i in range(n)]
print((max(maxcost(li,n,0,0,dp),maxcost(li,n,0,1,dp),maxcost(li,n,0,2,dp))))

# Optimized solution
import sys
def maxcost(li,n):
    dp=[[-1 for j in range(3)] for i in range(n)]
    dp[n-1][0],dp[n-1][1],dp[n-1][2]=li[n-1][0],li[n-1][1],li[n-1][2]
    for i in range(n-2,-1,-1):
        for j in range(3):
            mx=-sys.maxsize
            for k in range(3):
                if j!=k:
                    mx=max(mx,dp[i+1][k]+li[i][j])
            dp[i][j]=mx
    return max(dp[0][0],dp[0][1],dp[0][2])

n=int(eval(input()))
li=[]
for i in range(n):
    temp=[int(x) for x in input().split()]
    li.append(temp)
print((maxcost(li,n)))
# Original solution
#https://atcoder.jp/contests/dp/tasks/dp_c
N = int(eval(input()))

p = [list(map(int,input().split())) for l in range(N)]
dp = [[0,0,0]]*N
dp[0] = p[0]

for i in range(1,N,1):
    dp[i] = [0,0,0]#この文がないとバグる、理由はわからん
    #print(dp)
    for j in range(3):
        for k in range(3):
            if k != j:
                dp[i][j] = max(dp[i][j],dp[i-1][k] + p[i][j])
                #print(i,j,dp[i][j])


print((max(max(dp))))

# Optimized solution
#動的計画法
#C - Vacation
#aのところをdp[i][0]とするとなぜか事故る、そういう仕様なのか？、それどもdp = [[0,0,0]]*Nが影響しているのか
N = int(eval(input()))
H = [list(map(int,input().split())) for i in range(N)]
dp = [[0,0,0]]*N
dp[0] = H[0]
for i in range(1,N):
    a = max(dp[i-1][1],dp[i-1][2])+H[i][0]
    b = max(dp[i-1][0],dp[i-1][2])+H[i][1]
    c = max(dp[i-1][0],dp[i-1][1])+H[i][2]
    dp[i] = [a,b,c]
print((max(dp[N-1])))
# Original solution
N = int(eval(input()))
H = []
for _ in range(N):
    h = tuple(map(int, input().split()))
    H.append(h)

dp = [H[0]]
for i in range(1, N):
    dp.append([
        max(dp[i-1][1] + H[i][0], dp[i-1][2] + H[i][0]),
        max(dp[i-1][0] + H[i][1], dp[i-1][2] + H[i][1]),
        max(dp[i-1][0] + H[i][2], dp[i-1][1] + H[i][2]),
    ])
print((max(dp[-1])))


# Optimized solution
N = int(eval(input()))
H = []
for _ in range(N):
    h = tuple(map(int, input().split()))
    H.append(h)

dp = H[0]
for i in range(1, N):
    a, b, c = H[i]
    dp_next = [
        max(dp[1] + a, dp[2] + a),
        max(dp[0] + b, dp[2] + b),
        max(dp[0] + c, dp[1] + c),
    ]
    dp = dp_next

print((max(dp)))
# Original solution
N = int(eval(input()))

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

a,b,c = [int(i) for i in input().split()]
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

for i in range(1,N):
    li = [int(i) for i in input().split()]
    for j in range(3):
        tmp = []
        for k in range(3):
            if j != k:
                tmp.append(dp[i-1][k] + li[j])
        dp[i][j] = max(tmp)

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


# Optimized solution
N = int(eval(input()))
A = [[int(i) for i in input().split()] for _ in range(N)]

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

for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j]+A[i][k])

print((max(dp[-1])))
# Original solution
class Solver(object):
    def __init__(self, N, happy):
        self.dp = [[99999999 for _ in range(3)] for _ in range(N)]
        self.N = N
        self.happy = happy

    def solve(self):
        happy_list = self.happy
        self.dp[0] = happy_list[0]
        for i in range(1, self.N):
            self.dp[i][0] = max(happy_list[i][0] + self.dp[i-1][1],
                                happy_list[i][0] + self.dp[i-1][2])
            self.dp[i][1] = max(happy_list[i][1] + self.dp[i-1][0],
                                happy_list[i][1] + self.dp[i-1][2])
            self.dp[i][2] = max(happy_list[i][2] + self.dp[i-1][0],
                                happy_list[i][2] + self.dp[i - 1][1])
        return max(self.dp[-1])


def main():
    N = int(eval(input()))
    happy = [[int(i) for i in input().split()] for _ in range(N)]
    solver = Solver(N, happy)
    print((solver.solve()))


if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]
    dp = [[None, None, None] for _ in range(N)]

    dp[0] = happy_list[0]

    for i in range(1, N):
        dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2])
        dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2])
        dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1])

    return max(dp[-1])


if __name__ == "__main__":
    print((main()))
# Original solution
import sys
n = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

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

p[0] = L[0].copy()
#print(p)
#print(L)

for d in range(1, n):
    for i in range(3):
        if i ==0:
            p[d][0] = max(p[d-1][1], p[d-1][2]) + L[d][0]
        elif i ==1:
            p[d][1] = max(p[d-1][0], p[d-1][2]) + L[d][1]
        elif i==2:
            p[d][2] = max(p[d-1][0], p[d-1][1]) + L[d][2]

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

# Optimized solution
import sys
n = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
#print(L)

dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = L[0].copy()

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + L[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + L[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + L[i][2]

print((max(dp[-1])))
# Original solution

from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)
n = int(eval(input()))
arr = []
for i in range(n):
    arr.append([int(i) for i in input().split()])

@lru_cache(None)
def cal(i,action):
    if i>=len(arr):
        return 0

    if action==0:
        return max(cal(i+1,1)+arr[i][1],cal(i+1,2)+arr[i][2])

    elif action==1:
        return max(cal(i+1,0)+arr[i][0],cal(i+1,2)+arr[i][2]) 
    
    else:
        return max(cal(i+1,1)+arr[i][1],cal(i+1,0)+arr[i][0])
    

print((max(cal(0,0),cal(0,1),cal(0,2))))

# Optimized solution

import sys
sys.setrecursionlimit(10**9)
n = int(eval(input()))
arr = []
for i in range(n):
    arr.append([int(i) for i in input().split()])

dp = [[-1 for i in range(n+2)] for i in range(3)]

def cal(i,action):

    if i>=len(arr):
        return 0

    if dp[action][i]==-1:
        if action==0:
            dp[action][i] = max(cal(i+1,1)+arr[i][1],cal(i+1,2)+arr[i][2])

        elif action==1:
            dp[action][i] = max(cal(i+1,0)+arr[i][0],cal(i+1,2)+arr[i][2]) 
        
        else:
            dp[action][i] = max(cal(i+1,1)+arr[i][1],cal(i+1,0)+arr[i][0])
        
    return dp[action][i]
print((max(cal(0,0),cal(0,1),cal(0,2))))
# Original solution
n=int(eval(input()))
data=[]
t=[[0 for x in range(4)] for w in range(n+1)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
for i in range(1,n+1):
    for j in range(1,4):
        large=0
        for w in range(1,4):
            if(w==j):
                continue
            else:
                if(t[i-1][w]>large):
                    large=t[i-1][w]
        t[i][j]=data[i-1][j-1]+large
print((max(t[-1])))

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def solve(n,pos):
    global data,helper
    if(n==-1):
        return 0
    if(helper[n][pos]!=-1):
        return helper[n][pos]
    if(pos==0):
        helper[n][pos]=max(data[n][1]+solve(n-1,1),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    elif(pos==1):
        helper[n][pos] = max(data[n][0]+solve(n-1,0),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    else:
        helper[n][pos] = max(data[n][1]+solve(n-1,1),data[n][0]+solve(n-1,0))
        return helper[n][pos]
n=int(eval(input()))
data=[]
helper=[[-1 for y in range(3)] for x in range(n)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
t1=data[-1][0]+solve(n-2,0)
t2=data[-1][1]+solve(n-2,1)
t3=data[-1][2]+solve(n-2,2)
print((max(t1,t2,t3)))
# Original solution
def resolve():
	n = int(eval(input()))
	dp = [[0]*3 for _ in range(n+1) ]
	for i in range(1, n+1):
		r = list(map(int, input().split()))
		for j in range(3):
			for k in range(3):
				if j == k:
					continue
				dp[i][j] = max(dp[i][j], dp[i-1][k] + r[j])
	print((max(dp[-1])))
resolve()

# Optimized solution
def resolve():
	n = int(eval(input()))
	dp = [[0]*3 for _ in range(n+1)]
	for i in range(1, n+1):
		nums = list(map(int, input().split()))
		for j in range(3):
			for k in range(3):
				if j == k:
					continue
				dp[i][j] = max(dp[i][j], nums[j] + dp[i-1][k])
	print((max(dp[-1])))
resolve()
# Original solution
N = int(eval(input()))
dp = [[0 for i in range(3)] for i in range(N+1)]
for i in range(N):
    a, b, c = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
print((max(dp[N])))


# Optimized solution
N = int(eval(input()))
dp = [[0]*3 for i in range(N+1)]

for i in range(N):
    a, b, c = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1] + a, dp[i][2] + a, dp[i][0])
    dp[i+1][1] = max(dp[i][2] + b, dp[i][0] + b, dp[i][1])
    dp[i+1][2] = max(dp[i][0] + c, dp[i][1] + c, dp[i][2])

print((max(dp[N])))
# Original solution


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(eval(input()))

# 「翌日の値をセット」しているので、最終日+1日まで入る関係で+1
dp = [ [0 for _ in range(3)] for _ in range(N+1) ]
#print(dp)

ABC = [[]] * N

for i in range(N):
    x = list(map(int, input().split()))
    ABC[i] = x

#print(ABC)

# i日目
for i in range(N):
    '''
             j                     k
    dp[ i ][ 0 ] から dp[ i + 1 ][ 0 ] はcontinue(以下略）
    dp[ i ][ 0 ] から dp[ i + 1 ][ 1 ] への遷移(ABC[i][1])
    dp[ i ][ 0 ] から dp[ i + 1 ][ 2 ] への遷移(ABC[i][2])
    dp[ i ][ 1 ] から dp[ i + 1 ][ 0 ] への遷移(ABC[i][0])
    dp[ i ][ 1 ] から dp[ i + 1 ][ 2 ] への遷移(ABC[i][2])
    dp[ i ][ 2 ] から dp[ i + 1 ][ 0 ] への遷移(ABC[i][0])
    dp[ i ][ 2 ] から dp[ i + 1 ][ 1 ] への遷移(ABC[i][1])
    '''
    # i日目の選択肢
    for j in range(3):
        # i+1日目の選択肢
        for k in range(3):
            # 翌日が今日と同じならパス
            if j == k:
                continue

            ### 配るdp
            # 翌日の活動kと、今日の幸福度+選択した活動を比較
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+ABC[i][k])

ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])

print(ans)


# Optimized solution

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(eval(input()))
A = []
B = []
C = []
for i in range(N):
    a, b, c = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    C.append(c)

dp = [ [0 for _ in range(3)] for _ in range(N+1) ]

for i in range(1, N+1):
    dp[i][0] = max(dp[i-1][1]+B[i-1], dp[i-1][2]+C[i-1])
    dp[i][1] = max(dp[i-1][0]+A[i-1], dp[i-1][2]+C[i-1])
    dp[i][2] = max(dp[i-1][0]+A[i-1], dp[i-1][1]+B[i-1])

print((max(dp[N])))
# Original solution
N=int(eval(input()))
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	DP[i]=[ABC[i][0]+max(DP[i-1][1],DP[i-1][2]),ABC[i][1]+max(DP[i-1][0],DP[i-1][2]),ABC[i][2]+max(DP[i-1][1],DP[i-1][0])]
print((max(DP[N-1])))

# Optimized solution
N=int(eval(input()))
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N+1)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print((max(DP[N-1])))
# Original solution
N=int(eval(input()))
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N+1)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print((max(DP[N-1])))



# Optimized solution
N=int(eval(input()))
ABC=[[0,0,0]]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N+1)]
for i in range(N):
	for j in range(3):
		DP[i+1][j]=ABC[i+1][j]+max(DP[i][(j+1)%3],DP[i][(j+2)%3])
print((max(DP[N])))
# Original solution
N=int(eval(input()))
dp=[[0]*3 for i in range(N+1)]#今回は正の範囲で最大値をもとめたいので0で初期化
for i in range(N):
  a=list(map(int,input().split()))
  for j in range(3):
    for k in range(3):
      if k!=j:
        dp[i+1][j]=max(dp[i][k]+a[j],dp[i+1][j])
print((max(dp[-1])))

# Optimized solution
N=int(eval(input()))
dp=[[0]*3 for i in range(N+1)]
for i in range(N):
  a=list(map(int,input().split()))
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i][k]=max(dp[i][k],dp[i-1][j]+a[k])
print((max(dp[N-1])))
# Original solution
# dp[i日目][i-1日目にどれを選んだか] = i日目までの最大の幸福度
import sys
sys.setrecursionlimit(10 ** 8)

n = int(eval(input()))
a, b, c = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)]
for i in range(n):
    a[i], b[i], c[i] = list(map(int, input().split()))

dp = [[-1 for _ in range(3)] for _ in range(n + 1)]
for i in range(3):
    dp[0][i] = 0


def rec(i, choice):
    if dp[i][choice] > 0:
        return dp[i][choice]
    if i == n:
        return 0
    ret = 0  # ループじゃなくてifでやってるのでそれぞれ確実に大きい値が入る（ので更新する必要がない）
    if choice == 0:
        ret = a[i] + max(rec(i + 1, 1), rec(i + 1, 2))
    elif choice == 1:
        ret = b[i] + max(rec(i + 1, 0), rec(i + 1, 2))
    elif choice == 2:
        ret = c[i] + max(rec(i + 1, 0), rec(i + 1, 1))
    dp[i][choice] = ret
    return ret


print((max(rec(0, 0), rec(0, 1), rec(0, 2))))


# Optimized solution
# dp[i日目][i-1日目にどれを選んだか] = i日目までの最大の幸福度
# これはループでやってみたバージョン

n = int(eval(input()))
a, b, c = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)]
for i in range(n):
    a[i], b[i], c[i] = list(map(int, input().split()))

dp = [[-1 for _ in range(3)] for _ in range(n + 1)]
# 初期値、最初間違えて0にしてた
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for i in range(1, n):
    for j in range(3):
        if j == 0:
            dp[i][j] = a[i] + max(dp[i - 1][1], dp[i - 1][2])
        elif j == 1:
            dp[i][j] = b[i] + max(dp[i - 1][0], dp[i - 1][2])
        elif j == 2:
            dp[i][j] = c[i] + max(dp[i - 1][1], dp[i - 1][0])
print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))
# Original solution
N = int(eval(input()))
dp = [[0 for _ in range(3)] for i in range(N)]
a,b,c = list(map(int,input().split()))
dpa = a
dpb = b
dpc = c
for i in range(1,N):
    dpap = dpa
    dpbp = dpb
    dpcp = dpc
    a,b,c = list(map(int,input().split()))
    dpa = max(dpbp + a, dpcp + a)
    dpb = max(dpap + b, dpcp + b)
    dpc = max(dpap + c, dpbp + c)
print((max(dpa,dpb,dpc)))



# Optimized solution
N = int(eval(input()))
a,b,c = list(map(int,input().split()))
dpa = a
dpb = b
dpc = c
for i in range(1,N):
    dpap = dpa
    dpbp = dpb
    dpcp = dpc
    a,b,c = list(map(int,input().split()))
    dpa = max(dpbp + a, dpcp + a)
    dpb = max(dpap + b, dpcp + b)
    dpc = max(dpap + c, dpbp + c)
print((max(dpa,dpb,dpc)))
# Original solution
#!/usr/bin/env python3
import sys
import collections
import itertools

def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = collections.defaultdict(int)

    for i,x in enumerate([a,b,c]):
        dp[0,i] = x[0]

    for i,abc in itertools.islice(enumerate(zip(a,b,c)),1,None):
        for p,q in ((p,q) for p in range(3) for q in range(3) if p != q):
            dp[i,p] = max(dp[i,p], dp[i-1,q] + abc[p])

    print((max([dp[N-1,c] for c in range(3)])))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    c = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, a, b, c)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = [[0 for _ in range(3)] for _ in range(N)]

    H = list(zip(a,b,c))

    for j in range(3):
        dp[0][j] = H[0][j]

    for i in range(1,N):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j],dp[i-1][k] + H[i][j])

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


    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, a, b, c)

if __name__ == '__main__':
    main()
# Original solution
def LIST():
    return list(map(int, input().split()))
N = int(eval(input()))
arr = [LIST() for _ in range(N)]
dp = [[arr[0][0],arr[0][1],arr[0][2]],[0,0,0]]
l=1
p=0
for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j == k: continue
            a1=dp[p][j]
            a2=arr[i][k]
            a3=a1+a2
            dp[l][k] = max(dp[l][k], dp[p][j] + arr[i][k])
    l=l^1
    p=p^1
            
print((max([dp[p][j] for j in range(3)])))

# Optimized solution
N=int(eval(input()))
arr = [int(a) for a in input().split()]
dp = [[arr[0],arr[1],arr[2]],[0,0,0]]
l=1
p=0
for i in range(1, N):
    arr = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j == k: continue
            dp[l][k] = max(dp[l][k], dp[p][j] + arr[k])
    l=l^1
    p=p^1
            
print((max([dp[p][j] for j in range(3)])))
# Original solution
import sys

sys.setrecursionlimit(200000)

n = int(eval(input()))
 
def dp(i, a, b, c):
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print((dp(n-1, a=True, b=True, c=True)))


# Optimized solution
import sys

sys.setrecursionlimit(200000)

n = int(eval(input()))
 
m ={}
def dp(i, a, b, c):
	if (i,a,b,c) in m:
		return m[(i,a,b,c)]
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	m[(i,a,b,c)] = max([a_v, b_v, c_v])
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print((dp(n-1, a=True, b=True, c=True)))
# Original solution
N = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(N)]

table = [a[0]]
def dp(n, i):
  for j in range(len(table), n+1):
    table.append([0]*3)
    for k in range(3):
      h = [table[j-1][l]+a[j][k] for l in range(3) if k != l]
      table[j][k] = max(h)
  return table[n][i]

print((max([dp(N-1, i) for i in range(3)])))

# Optimized solution
N = int(eval(input()))

dp = [[0]*3 for _ in range(N)]
dp[0] = list(map(int, input().split()))

for i in range(1, N):
  h = list(map(int, input().split()))
  for j in range(3):
    dp[i][j] = max([dp[i-1][k]+h[j] for k in range(3) if k != j])

print((max([dp[N-1][j] for j in range(3)])))
# Original solution
dp = [[0] * 3 for i in range(100010)]

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

for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][k] = max(dp[i][k], dp[i-1][j] + a[i-1][k])

print((max(dp[N])))


# Optimized solution
N = int(eval(input()))
a = [[0] * 3 for _ in range(N)]
for i in range(N):
    a[i][0], a[i][1], a[i][2] = list(map(int, input().split()))

dp = [[0] * 3 for _ in range(N+1)]

for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            #前の値がdp[i-1][j]で今選んでいるのがa[i-1][k]
            dp[i][k] = max(dp[i][k], dp[i-1][j] + a[i-1][k])

print((max(dp[N])))
# Original solution
n = int(eval(input()))

dpa, dpb, dpc = 0, 0, 0

for i in range(n):
    a, b, c = list(map(int, input().split()))
    dpa, dpb, dpc = max(dpb, dpc) + a, max(dpa, dpc) + b, max(dpa, dpb) + c

print((max(dpa, dpb, dpc)))


# Optimized solution
n = int(eval(input()))
da, db, dc = 0, 0, 0

for i in range(n):
    a, b, c = list(map(int, input().split()))
    da, db, dc = max(db, dc) + a, max(da, dc) + b, max(da, db) + c

print((max(da, db, dc)))