CodeEff/ECCO huggingface dataset:
# Original solution
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(eval(input()))
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = {}
def rp(i, p, h):
    global a,b,c,n
    if i >= n:
        return h
    
    av = [rp(i+1, 0, h+a[i]), rp(i+1, 1, h+b[i]), rp(i+1, 2, h+c[i])]
    if p != -1:
        av[p] = 0
    ans = max(av)
    return ans
ans = rp(0, -1, 0)
print(ans)
        
    
 


# Optimized solution
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(eval(input()))
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
    global a,b,c,n
    if i >= n:
        return 0
    if mem[i][p] != -1:
        return mem[i][p]
    av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
    if p != -1:
        av[p] = 0
    ans = max(av)
    mem[i][p] = ans
    return ans
ans = rp(0, -1)
print(ans)
        
    
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# maybe because the values that come later on decide more on what you choose?
# Original solution
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(eval(input()))
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
    global a,b,c,n
    if i >= n:
        return 0
    if mem[i][p] != -1:
        return mem[i][p]
    av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
    if p != -1:
        av[p] = 0
    ans = max(av)
    mem[i][p] = ans
    return ans
ans = rp(0, -1)
print(ans)
        
    
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# because state-cases below will not carry values from above, they only take values from below




# Optimized solution
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(eval(input()))
d = []
for i in range(n):
    d.append(gil())
dp = [[0,0,0]]
for dz in range(n):
    ndp = [0] * 3
    for i in range(3):
        for j in range(3):
            if i != j:
                ndp[i] = max(ndp[i], dp[dz][j] + d[dz][i])
    dp.append(ndp)
#print(dp)
print((max(dp[-1])))

    
# tabular approach
# Original solution
N=int(eval(input()))
H=[[0,0,0]]+[ list(map(int, input().split())) for _ in range(N) ]

#print(N,H)

def chmax(dp, n, k, a):
	b = (dp[n][k]<a)
	if b: dp[n][k]=a
	return b


#dp=[[0,0,0,0,0,0] for _ in range(N+1)]
dp=[[0,0,0] 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
			chmax(dp,i,k, dp[i-1][j] + H[i][k])
	

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


# Optimized solution
INF  = float("inf") # 正の無限大

N = int(eval(input()))						# 5

A=[0]*N
B=[0]*N
C=[0]*N

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


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

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


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

#print(dp)
# Original solution
N = int(eval(input()))
plans = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (3) for _ in range(N+1)]

def chmax(a, b):
    if a >= b:
        return a
    else:
        return b

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            else:
                dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + plans[i][k])
                
res = 0
for j in range(3):
    res = chmax(res, dp[-1][j])
print(res)

# Optimized solution
N = int(eval(input()))
h = [list(map(int, input().split())) for _ in range(N)] #1-index

def chmax(a,b):
    if a >= b:
        return a
    else:
        return b
dp = [[0]*(3) for _ in range(N+2)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if (j == k): continue
            dp[i+1][k] = chmax(dp[i+1][k], dp[i][j] + h[i][k])

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

n = int(eval(input()))

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

def happy(n, a):
    d = [[0] * 3 for j in range(n)]
    for i in range(3):
        d[0][i] = a[0][i]

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

    return max(d[n - 1])

print((happy(n, a)))


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

n = int(eval(input()))

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

def happy(n, abc):
    da, db, dc = 0, 0, 0
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(dc, da) + b
        nc = max(da, db) + c
        da, db, dc = na, nb, nc

    return max(da, db, dc)

print((happy(n, abc)))
# Original solution
n = int(eval(input()))

INF = 1 << 20
dp = [[INF] * (n + 1) for _ in range(3)]

# dp初期化
for i in range(3):
    dp[i][-1] = 0

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

print((max(list(zip(*dp))[n - 1])))

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

INF = 1 << 60
dp = [[INF] * n + [0] for _ in range(3)]

# 直前の行動と次の行動だけシミュレーションすればよい
for i in range(n):
    a, b, c = list(map(int, input().split()))
    dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a
    dp[1][i] = max(dp[2][i - 1], dp[0][i - 1]) + b
    dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c

print((max(list(zip(*dp))[n - 1])))
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

# Optimized solution
import sys
input = sys.stdin.readline
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()))

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]
print((max(dpa[-1],dpb[-1],dpc[-1])))
# Original solution
def main():
    N = int(eval(input()))
    abc = [list(map(int, input().split())) for _ in range(N)]

    DP = [[0, 0, 0] for _ in range(N)]
    DP[0] = abc[0]

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

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

main()


# Optimized solution
def main():
    N = int(eval(input()))
    abc = [list(map(int, input().split())) for _ in range(N)]

    DP = [[0, 0, 0] for _ in range(N)]
    DP[0] = abc[0]

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

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

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
abc = [[int(i) for i in input().split()] for i in range(N)]

for i in range(1,N):
    for g in range(3):
        abc[i][g] += max(abc[i-1][g-1], abc[i-1][g-2])

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

# Optimized solution
n=int(eval(input()))
abc=[list(map(int,input().split())) for _ in range(n)]

for i in range(1,n):
    abc[i][0]=abc[i][0]+max(abc[i-1][1],abc[i-1][2])
    abc[i][1]=abc[i][1]+max(abc[i-1][0],abc[i-1][2])
    abc[i][2]=abc[i][2]+max(abc[i-1][0],abc[i-1][1])
print((max(abc[-1])))
# Original solution
N = int(eval(input()))
L = []
for i in range(N) :
    L.append(list(map(int,input().split())))

dp = [[0,0,0] for i in range(N+1)]

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


# Optimized solution
N = int(eval(input()))
L = [list(map(int,input().split())) for i in range(N)]
NOW = [0,0,0]
NEXT = [None,None,None]

for i in range(N) :
    NEXT[0] = max(NOW[1],NOW[2]) + L[i][0]
    NEXT[1] = max(NOW[2],NOW[0]) + L[i][1]
    NEXT[2] = max(NOW[0],NOW[1]) + L[i][2]
    
    NOW = NEXT.copy()
print((max(NOW)))
# Original solution
N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]

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

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

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

x = y = z = 0
for a,b,c in A:
  x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c
print((max(x,y,z)))
# Original solution
N = int(eval(input()))
A = [[int(i) for i in input().split()] for _ in range(N)]

x = y = z = 0
for a, b, c in A:
  x, y, z = max(y, z)+a, max(x,z)+b, max(x,y)+c
print((max(x, y, z)))

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

x = y = z = 0
for _ in range(N):
  a, b, c = list(map(int,input().split()))
  x, y, z = max(y, z)+a, max(x,z)+b, max(x,y)+c
print((max(x, y, z)))
# Original solution
n = int(eval(input()))
ABC = [list(map(int, input().split())) for i in range(n)]

# i日目にjを選択した後の幸福度 dp[i][j]
dp = [[0 for j in range(3)] for i in range(n + 1)]

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

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


# Optimized solution
import sys


def input():
    return sys.stdin.readline().strip()


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

# i日目にjを選択した後の幸福度 dp[i][j]
dp = [[0 for j in range(3)] for i in range(n + 1)]

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

print((max(dp[-1])))
# Original solution
n = int(eval(input()))
dp = list(list(map(int, input().split())) for _ in range(n))
for i in range(1, n):
    dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] += max(dp[i - 1][2], dp[i - 1][0]);
    dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
print((max(dp[n - 1])))


# Optimized solution
import sys
readline = sys.stdin.readline
n = int(eval(input()))
dp = list(list(map(int, readline().split())) for _ in range(n))
for i in range(1, n):
    dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] += max(dp[i - 1][2], dp[i - 1][0]);
    dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
print((max(dp[n - 1])))
# Original solution
def MAP(): return list(map(int,input().split()))
def INT(): return int(eval(input()))
def FLOAT(): return float(eval(input()))
MOD = 10**9+7

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

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

print((max(dp[n])))

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

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

for i in range(n):
    a.append(list(map(int,input().split())))

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

print((max(dp[n])))
# Original solution
n=int(eval(input()))
al=[0]+[list(map(int,input().split())) for _ in range(n)]
dp=[[0,0,0] for _ in range(n+1)]
for day in range(1,n+1):
  for i in range(3):
    for j in range(3):
      if i==j:continue
      dp[day][i]=max(dp[day-1][j]+al[day][i],dp[day][i])
print((max(dp[-1])))

# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=[[float("INF")]*3 for i in range(n)]
l[0]=list(map(int,input().split()))
for day in range(1,n):
    f=list(map(int,input().split()))
    for choice in range(3):
        l[day][choice]=max(l[day-1][j]+f[choice] for j in range(3) if j!=choice)
print((max(l[-1])))
# Original solution
#import sys
#input = sys.stdin.readline

n = int(eval(input()))
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])
dp = [[float("inf") for i in range(3)] for i in range(n)]

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


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

n = int(eval(input()))

for i in range(n):
    if i == 0:
        dp = [int(i) for i in input().split()]
    else:
        abc = [int(i) for i in input().split()]
        dp[0], dp[1], dp[2] = abc[0] + max(dp[1], dp[2]), abc[1] + max(dp[0], dp[2]), abc[2] + max(dp[0], dp[1])
    
print((max(dp)))
# Original solution
N=int(eval(input()))
act=[]
for i in range(N):
    act.append(list(map(int,input().split())))
dp=[[0]*3 for i in range(N+1)]

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

# Optimized solution
N=int(eval(input()))
dp=[[0,0,0] for i in range(N+1)]
for i in range(1,N+1):
    a,b,c=list(map(int,input().split()))
    dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a)
    dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b)
    dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c)
print((max(dp[N])))
# Original solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    abc = [0] * N
    for i in range(N):
        abc[i] = list(map(int, input().split()))

    dp = [[0] * 3 for _ in range(N)]
    dp[0] = abc[0]
    for i, (a, b, c) in enumerate(abc[1:], start=1):
        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

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


if __name__ == "__main__":
    main()


# Optimized solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    abc = [0] * N
    for i in range(N):
        abc[i] = list(map(int, input().split()))

    dp = [[0] * 3 for _ in range(N)]
    dp[0] = abc[0]
    for i, (a, b, c) in enumerate(abc[1:], start=1):
        dp_i = dp[i]
        dp_im = dp[i - 1]
        dp_i[0] = max(dp_im[1], dp_im[2]) + a
        dp_i[1] = max(dp_im[0], dp_im[2]) + b
        dp_i[2] = max(dp_im[0], dp_im[1]) + c

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


if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
dp=[[0 for i in range(3)] for j 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+1][1]=max(dp[i][0]+b,dp[i][2]+b)
  dp[i+1][2]=max(dp[i][1]+c,dp[i][0]+c)
  
print((max(dp[N])))


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

N = int(readline())
dp = [[0] * 3 for i in range(N + 1)]

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

# 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):
    l=list(map(int,input().split()))
    dp[i][0]=l[0]+max(dp[i-1][1],dp[i-1][2])
    dp[i][1]=l[1]+max(dp[i-1][0],dp[i-1][2])
    dp[i][2]=l[2]+max(dp[i-1][0],dp[i-1][1])
print((max(dp[-1])))
# Original solution
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])))

# Optimized solution
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])))
# Original solution
from pprint import pprint
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(1,n):
    for j in range(3):
        dp[i][j]=max(dp[i-1][(j+1)%3]+l[i][j],dp[i-1][(j+2)%3]+l[i][j])
print((max(dp[n-1])))
# pprint(dp)

# Optimized solution
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]+l[i+1][j],dp[i][(j+2)%3]+l[i+1][j])
print((max(dp[n-1])))
# Original solution
N = int(eval(input()))
ABC = [list(map(int,input().split())) for _ in range(N)]

dp = [[0 for i in range(3)] for j in range(N)]
dp[0][0]= ABC[0][0]
dp[0][1]= ABC[0][1]
dp[0][2]= ABC[0][2]
for i in range(1,N):
    for toi in range(3):
        s = 0
        for fromi in range(3):
            if toi==fromi:
                continue
            s = max(s, dp[i-1][fromi] + ABC[i][toi])
        dp[i][toi] = s


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

# Optimized solution
N = int(eval(input()))
ABC = [list(map(int,input().split())) for _ in range(N)]

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

# 1日目の初期化
dp[0]= ABC[0]
for i in range(1,N):
    # 次ステップでA,B,Cに行く場合、
    for toi in range(3):
        s = 0
        # どこから来るのが最大か求める
        for fromi in range(3):
            # 同じ行動はとらない
            if toi==fromi:
                continue
            s = max(s, dp[i-1][fromi] + ABC[i][toi])
        dp[i][toi] = s

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

p=list(map(int,input().split()))

for i in range(1,N):
    add=list(map(int,input().split()))
    temp=[[] for j in range(3)]
    for j in range(3):
        pnt=p[j]
        for k in range(3):
            if j==k:continue
            else:
                temp[k].append(pnt+add[k])
    for j in range(3):
        p[j]=max(temp[j])
print((max(p)))

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

p=list(map(int,input().split()))

for i in range(1,N):
    add=list(map(int,input().split()))
    p0=p[0]
    p1=p[1]
    p2=p[2]
    p[0]=max(add[0]+p1,add[0]+p2)
    p[1]=max(add[1]+p2,add[1]+p0)
    p[2]=max(add[2]+p0,add[2]+p1)

print((max(p)))
# Original solution
n = int(eval(input()))

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

dp = [[0] * 3 for _ in range(n)]
dp[-1] = [a[-1], b[-1], c[-1]]

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

print((max(dp[0])))

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

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

dp = [[0] * n for _ in range(3)]
dp[0][-1], dp[1][-1], dp[2][-1] = a[-1], b[-1], c[-1]

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

print((max(dp[0][0], dp[1][0], dp[2][0])))
# Original solution
n = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(n)]

def chmax(a, b):
    if a > b:
        return a
    else:
        return b

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

for i in range(3):
    dp[0][i] = A[0][i]

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

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

# Optimized solution
n = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(n)]

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

for i in range(3):
    dp[0][i] = A[0][i]

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[n-1])))
# Original solution
n = int(eval(input()))
A = [[int(i) for i in input().split()] for i in range(n)]
dp = [0, 0, 0]

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

# Optimized solution
n = int(eval(input()))
dp = [int(i) for i in input().split()]

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    dp = [max(dp[1], dp[2]) + a, max(dp[0], dp[2]) + b, max(dp[0], dp[1]) + c]
    
print((max(dp)))
# Original solution
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())
abc = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
# add dummy
abc = abc + [[-INF, -INF, -INF]]

# i日目に(0, 1, 2):=(a, b, c)の行動を行った時の幸福度の最大値
dp = [[-INF] * 3 for _ in range(N+10)]

a, b, c = abc[0]
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

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

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


# Optimized solution
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())
abc = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

# i日目に(0, 1, 2):=(a, b, c)の行動を行った時の幸福度の最大値
dp = [[-INF] * 3 for _ in range(N+10)]

a, b, c = abc[0]
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

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

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