CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(N)]

dp = []
for i in range(N+1):
    dp.append([0] * 3)

for j in range(1, N+1):
    for k in range(3):
        if j == 1:
            dp[j][k] = abc[0][k]
        else:
            box = []
            for l in range(3):
                if l == k:
                    continue
                else:
                    box.append(dp[j-1][l] + abc[j-1][k])
            dp[j][k] = max(dp[j][k], max(box))
print((max(dp[N])))


# Optimized solution
N = int(eval(input()))
dpa = [0] * N
dpb = [0] * N
dpc = [0] * N

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

print((max(dpa[N-1], dpb[N-1], dpc[N-1])))
# Original solution
from functools import lru_cache
import sys 
sys.setrecursionlimit(2147483647)

N = int(eval(input()))
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

@lru_cache(None)
def dfs(d,pre):
    if d>=N-1: return 0
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            tmp.append(res)
    return max(tmp)

print((dfs(-1,-1)))

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

dp = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    for j in range(3):
        if i == 0:
            dp[i][j]= A[i][j]
        else:
            tmp = [0] 
            for k in range(3):
                if j !=k:
                    tmp.append(dp[i-1][k])
            dp[i][j] = max(tmp) + A[i][j]
print((max(dp[-1])))
# Original solution
n = int(eval(input()))
e = tuple(tuple(map(int, input().split())) for _ in range(n))

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

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

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


# Optimized solution
n = int(eval(input()))
v = tuple(tuple(map(int, input().split())) for _ in range(n))
e = tuple(zip(*v))
# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度
# print(e)

dp = tuple([0] * 3 for _ in range(n + 1))
# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度

# もらう
for i in range(n):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]
print((max(dp[n])))
# Original solution
n = int(eval(input()))
v = tuple(tuple(map(int, input().split())) for _ in range(n))
e = tuple(zip(*v))
# e[j][i(0-indexed)]:=i日目に活動jして得る幸福度
# print(e)

dp = tuple([0] * 3 for _ in range(n + 1))
# dp[i(1-indexed)][j]:=i日目に活動jした最大幸福度

# もらう
for i in range(n):
    for j in range(3):
        dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + e[j][i]
print((max(dp[n])))


# Optimized solution
def main():
    import sys
    readline = sys.stdin.readline

    n = int(readline())

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

    for i in range(1, n + 1):  # i日目の最大幸福度,1-indexed
        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][2], dp[i - 1][0]) + b
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c

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


if __name__ == '__main__':
    main()
# Original solution
def main():
    import sys
    readline = sys.stdin.readline

    n = int(readline())

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

    for i in range(1, n + 1):  # i日目の最大幸福度,1-indexed
        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][2], dp[i - 1][0]) + b
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c

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


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    import sys
    readline = sys.stdin.readline

    n = int(readline())

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

    for i in range(1, n + 1):  # i日目の最大幸福度,1-indexed
        a, b, c = list(map(int, readline().split()))
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + b
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c

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


if __name__ == '__main__':
    main()
# Original solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

def main():
    N = gete(int)
    p, q, r = 0,0,0
    for _ in range(N):
        a,b ,c = geta(int)
        p,q,r = a + max(q,r), b + max(r,p), c + max(p,q)

    print((max(p,q,r)))

if __name__ == "__main__":
    main()

# Optimized solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

def main():
    N = gete(int)
    a = [0]*(N+1)
    b, c = a[:], a[:]

    for i in range(N):
        av, bv, cv = geta(int)
        a[i+1] = av + max(b[i], c[i])
        b[i+1] = bv + max(c[i], a[i])
        c[i+1] = cv + max(a[i], b[i])

    print((max(a[-1], b[-1], c[-1])))

if __name__ == "__main__":
    main()
# Original solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

def main():
    N = gete(int)
    a = [0]*(N+1)
    b, c = a[:], a[:]

    for i in range(N):
        av, bv, cv = geta(int)
        a[i+1] = max(av + b[i], av + c[i])
        b[i+1] = max(bv + c[i], bv + a[i])
        c[i+1] = max(cv + a[i], cv + b[i])

    print((max(a[-1], b[-1], c[-1])))

if __name__ == "__main__":
    main()

# Optimized solution
# copy and paste (check calc time)
import sys
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
 
 
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
 
def main():
	n=int(eval(input()))
	dp=[[0]*3 for _ 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][2], dp[i][0]) + b
		dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
		
	print((max(dp[n][0],dp[n][1],dp[n][2])))
	
	
	
if __name__ == "__main__":
	main()
# Original solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

def main():
	n=gete(int)
	dp=[[0]*3 for _ 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][2], dp[i][0]) + b
		dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
		
	print((max(dp[n][0],dp[n][1],dp[n][2])))
	
	
	
if __name__ == "__main__":
	main()

# Optimized solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())

def main():
	n=gete(int)
	dp=[[0]*3 for _ in range(n+1)]
	
	
	for i in range(n):
		a,b,c = geta(int)
		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][0],dp[n][1],dp[n][2])))
	
	
	
if __name__ == "__main__":
	main()
# Original solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())

def main():
	n=gete(int)
	dp=[[0]*3 for _ in range(n+1)]
	
	
	for i in range(n):
		a,b,c = geta(int)
		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][0],dp[n][1],dp[n][2])))
	
	
	
if __name__ == "__main__":
	main()

# Optimized solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())

def main():
    N = gete(int)
 
    cur, prev = [0]*3, [0]*3
    
    for _ in range(N):
        a, b, c = geta(int)
        prev, cur = cur, prev
        cur[0] = max(prev[1], prev[2]) + a
        cur[1] = max(prev[2], prev[0]) + b
        cur[2] = max(prev[0], prev[1]) + c
    
    
    print((max(cur)))

	
if __name__ == "__main__":
	main()
# Original solution
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
abc = [LI() for _ in range(N)]
dp = [[0,0,0] for _ in range(N)]
dp[0] = abc[0]
for i,j,k in itertools.product(list(range(N)),[0,1,2],[0,1,2]):
    if j==k:
        continue
    if i-1>=0:
        dp[i][j] = max(dp[i][j],dp[i-1][k]+abc[i][j])
print((max(dp[-1])))


# Optimized solution
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
abc = [LI() for _ in range(N)]
dp = [[0,0,0] for _ in range(N)]
dp[0] = abc[0]
for i,j,k in itertools.product(list(range(1,N)),[0,1,2],[0,1,2]):
    if j==k:
        continue
    dp[i][j] = max(dp[i][j],dp[i-1][k]+abc[i][j])
print((max(dp[-1])))
# Original solution
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]

dp = [[0]*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]+a[i][k])
print((max(dp[-1])))

# Optimized solution
n=int(eval(input()))
a=[list(map(int,input().split())) for i in range(n)]
dp=[[a[0][0],a[0][1],a[0][2]]]+[[0]*3 for i in range(n-1)]
for i in range(1,n):
  for j in range(3):
    if j==0:
      dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i][0]
    elif j==1:
      dp[i][j]=max(dp[i-1][0],dp[i-1][2])+a[i][1]
    else:
      dp[i][j]=max(dp[i-1][1],dp[i-1][0])+a[i][2]
print((max(dp[n-1])))
# Original solution
N=int(eval(input()))
dp=[[0]*3 for _ in range(N+1)]
abc=[list(map(int,input().split())) for _ in range(N)]
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[N])))

# Optimized solution
def main():
    N=int(eval(input()))
    dp=[[0]*3 for _ in range(N+1)]
    abc=[list(map(int,input().split())) for _ in range(N)]
    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[N])))
    
if __name__ == '__main__':
    main()
# Original solution
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])))

# Optimized solution
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])))
# Original solution
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

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

# l = [[0 for _ in range(3)] for _ in range(N+10)]
@lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    return max_num

print((max(dp(N-1, m) for m in range(3))))


# Optimized solution
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

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

l = [[None for _ in range(3)] for _ in range(N+10)]
# @lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    if l[i][use] != None:
        return l[i][use]
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    l[i][use] = max_num 
    return max_num

print((max(dp(N-1, m) for m in range(3))))
# Original solution
import sys
sys.setrecursionlimit(10**6)

n = int(eval(input()))
a, b, c = [], [], []
# dp = [[None] * 3 for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]

for i in range(n):
    v1, v2, v3 = list(map(int, input().split()))
    a.append(v1)
    b.append(v2)
    c.append(v3)

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

def solve(idx, ptn):
    if dp[idx][ptn] > 0:
        return dp[idx][ptn]

    # Select A(0)
    if ptn == 0:
        if idx == 0:
            return a[0]
        a1 = solve(idx - 1, 1) + a[idx]
        a2 = solve(idx - 1, 2) + a[idx]
        dp[idx][0] = max(a1, a2)
        return dp[idx][0]

    # Select B(1)
    if ptn == 1:
        if idx == 0:
            return b[0]
        b1 = solve(idx - 1, 0) + b[idx]
        b2 = solve(idx - 1, 2) + b[idx]
        dp[idx][1] = max(b1, b2)
        return dp[idx][1]

    # Select C(2)
    if ptn == 2:
        if idx == 0:
            return c[0]
        c1 = solve(idx - 1, 0) + c[idx]
        c2 = solve(idx - 1, 1) + c[idx]
        dp[idx][2] = max(c1, c2)
        return dp[idx][2]

ans1 = solve(n-1, 0)
ans2 = solve(n-1, 1)
ans3 = solve(n-1, 2)
print((max(ans1, ans2, ans3)))

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

n = int(eval(input()))
a, b, c = [], [], []
# dp = [[None] * 3 for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]

for i in range(n):
    v1, v2, v3 = list(map(int, input().split()))
    a.append(v1)
    b.append(v2)
    c.append(v3)

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

for idx in range(1, n):
    # Select A(0)
    a1 = dp[idx - 1][1] + a[idx]
    a2 = dp[idx - 1][2] + a[idx]
    dp[idx][0] = max(a1, a2)

    # Select B(1)
    b1 = dp[idx - 1][0] + b[idx]
    b2 = dp[idx - 1][2] + b[idx]
    dp[idx][1] = max(b1, b2)

    # Select C(2)
    c1 = dp[idx - 1][0] + c[idx]
    c2 = dp[idx - 1][1] + c[idx]
    dp[idx][2] = max(c1, c2)

print((max(dp[n-1][0], dp[n-1][1], dp[n-1][2])))
# Original solution
N = int(eval(input()))
v = [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]+v[i][k])
            
print((max(dp[N][i] for i in range(3))))

# Optimized solution
def main():
    N = int(eval(input()))
    v = [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]+v[i][k])
    print((max(dp[N][i] for i in range(3))))
main()
# Original solution
N=int(eval(input()))
a=[]
for _ in range(N): 
    b=list(map(int,input().split()))
    a.append(b)
dp=[]
for _ in range(N):
    dp.append([0,0,0])
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]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0])
    dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1])
    dp[i][2]=max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2])
print((max(dp[N-1][0],dp[N-1][1],dp[N-1][2])))

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

n = int(eval(input()))
abc = [[int(x) for x in input().split()] for _ in range(n)]

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

pointA = [0]*N; pointB = [0]*N; pointC = [0]*N
pointA[0] = A[0]; pointB[0] = B[0]; pointC[0] = C[0]
for i in range(1, N):
    pointA[i] = max(pointB[i-1], pointC[i-1]) + A[i]
    pointB[i] = max(pointA[i-1], pointC[i-1]) + B[i]
    pointC[i] = max(pointA[i-1], pointB[i-1]) + C[i]
print((max((pointA[N-1], pointB[N-1], pointC[N-1]))))

# Optimized 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()))

lisA = [0]*N; lisB = [0]*N; lisC = [0]*N
lisA[0] = A[0]; lisB[0] = B[0]; lisC[0] = C[0];
for i in range(1, N):
    lisA[i] = max(lisB[i-1], lisC[i-1]) + A[i]
    lisB[i] = max(lisA[i-1], lisC[i-1]) + B[i]
    lisC[i] = max(lisA[i-1], lisB[i-1]) + C[i]

print((max(lisA[N-1], lisB[N-1], lisC[N-1])))
# Original solution
import sys
N = int(eval(input()))
A = [0] * N
B = [0] * N
C = [0] * N
for i, e in enumerate(sys.stdin):
    A[i], B[i], C[i] = list(map(int, e.split()))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
    dp[i][0] = max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i])
    dp[i][1] = max(dp[i - 1][0] + B[i], dp[i - 1][2] + B[i])
    dp[i][2] = max(dp[i - 1][0] + C[i], dp[i - 1][1] + C[i])
print((max(dp[N - 1])))

# Optimized solution
import sys
N = int(eval(input()))
x, y, z = 0, 0, 0
for i, e in enumerate(sys.stdin):
    a, b, c = list(map(int, e.split()))
    nx = max(y, z) + a
    ny = max(x, z) + b
    nz = max(x, y) + c
    x, y, z = nx, ny, nz
print((max(x, y, z)))
# Original solution
N=int(eval(input()))
#dp[i]...i日間で得られる幸福度の最大値
INF = 10**18
dp =[]
for _ in range(N):
    dp.append([INF] * (N+1))
dp[0] = list(map(int,input().split()))
#print(dp)
for i in range(1, N):
    #変えたいのはdp[1][0〜2]
    day = list(map(int,input().split()))
    d_temp = [dp[i-1][k]+day[j] for j in range(3) for k in range(3) if k!=j]
    #print(d_temp)
    dp[i]=[max(d_temp[2*x:2*x+2]) for x in range(3)]
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):
    a,b,c=list(map(int,input().split()))
    dp[i][0] = a+max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = b+max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = c+max(dp[i-1][0], dp[i-1][1])
print((max(dp[N-1])))
# Original solution
n=int(eval(input()))
satis=[]

for i in range(n):
  A=list(map(int,input().split()))
  satis.extend(A)

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print((max([tempA,tempB,tempC])))
else:
  print((max([tempA,tempB,tempC])))

# Optimized solution
n=int(eval(input()))
satis=[]

for i in range(n):
	satis.extend(list(map(int,input().split())))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print((max([tempA,tempB,tempC])))
else:
  print((max([tempA,tempB,tempC])))
# Original solution
# -*- coding: utf-8 -*-

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

dp = [[0] * N for _ in range(N)]
#print(dp)
dp[0] = Z[0]

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

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


# Optimized solution
# -*- coding: utf-8 -*-

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

dp = [[0] * 3 for _ in range(N)]
#print(dp)
dp[0] = Z[0]

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

print((max(dp[-1])))
# Original solution
n,*l=list(map(int,open(0).read().split()))
a=l[::3]
b=l[1::3]
c=l[2::3]
dp=[[0]*3 for _ in range(n)]
dp[0]=[a[0],b[0],c[0]]
A,B,C=dp[0]
for i in range(1,n):
	dp[i]=[ a[i]+max(B,C) , b[i]+max(C,A) , c[i]+max(A,B) ]
	A,B,C=dp[i]
print((max(dp[-1])))

# Optimized solution
n,*l=list(map(int,open(0).read().split()))
a=l[::3];b=l[1::3];c=l[2::3]
A,B,C=a[0],b[0],c[0]
M=max
for i in range(1,n):
	A,B,C=a[i]+M(B,C),b[i]+M(C,A),c[i]+M(A,B)
print((M(A,B,C)))
# Original solution
n = int(eval(input()))
a = [0]*(n+1)
b = [0]*(n+1)
c = [0]*(n+1)
for i in range(1,n+1): a[i],b[i],c[i] = list(map(int,input().split()))
dp = [[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        if j == 0: dp[i][j] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i])
        elif j == 1: dp[i][j] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i])
        else: dp[i][j] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i])
print((max(dp[n])))

# Optimized solution
n = int(eval(input()))
a = [0]*(n+1)
b = [0]*(n+1)
c = [0]*(n+1)
for i in range(1,n+1): a[i],b[i],c[i] = list(map(int,input().split()))
dp = [[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        if j == 0: dp[i][j] = max(dp[i-1][1],dp[i-1][2])+a[i]
        elif j == 1: dp[i][j] = max(dp[i-1][0],dp[i-1][2])+b[i]
        else: dp[i][j] = max(dp[i-1][0],dp[i-1][1])+c[i]
print((max(dp[n])))
# Original solution
N = int(eval(input()))
A = [0]*N
for i in range(N):
    A[i] = list(map(int, input().split()))
def solve(N,A):
    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] = max(dp[i-1][1],dp[i-1][2])+A[i][0]
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+A[i][1]
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+A[i][2]
    ans = max(dp[-1])
    return ans
print((solve(N,A)))

# Optimized solution
def solve():
  N = int(eval(input()))
  dp = [[float('inf')]*3 for _ in range(N)]
  dp[0] = list(map(int, input().split()))
  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
  ans = max(dp[-1])
  return ans
print((solve()))
# Original solution
n = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(n)]

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

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] + l[i][k])

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

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

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

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] + l[i][j])

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

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

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] + l[i][j])

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

# Optimized solution
n = int(eval(input()))
abc  = [[], [], []]

abc = [list(map(int, input().split())) for _ in range(n)] # DB取得方法のみ違う, 分かればどっちでもok
#print(abc)

dp = [[0,0,0] for _ in range(n)]
dp[0] = abc[0]
#print(dp)

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] + abc[i][j]) # ここのDB指定方法に影響

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