CodeEff/ECCO huggingface dataset:
# Original solution
N=int(eval(input()))
ABC=[]
for i in range(N):
  l=list(map(int,input().split()))
  ABC=ABC+[l]
dp=[[0,0,0] for i in range(N)]#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
for i in range(3):
  dp[0][i]=ABC[0][i]
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+ABC[i][1],dp[i-1][0]+ABC[i][1])
  dp[i][0]=max(dp[i-1][1]+ABC[i][0],dp[i-1][2]+ABC[i][0])
  dp[i][2]=max(dp[i-1][1]+ABC[i][2],dp[i-1][0]+ABC[i][2])
ans=max(dp[N-1])
print(ans)

# Optimized solution
N=int(eval(input()))
A=[]
B=[]
C=[]
for i in range(N):
  l1,l2,l3=list(map(int,input().split()))
  A+=[l1]
  B+=[l2]
  C+=[l3]
dp=[[0,0,0] for i in range(N)]#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
dp[0][0]=A[0]
dp[0][1]=B[0]
dp[0][2]=C[0]
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+B[i],dp[i-1][0]+B[i])
  dp[i][0]=max(dp[i-1][1]+A[i],dp[i-1][2]+A[i])
  dp[i][2]=max(dp[i-1][1]+C[i],dp[i-1][0]+C[i])
ans=max(dp[N-1])
print(ans)
# Original solution
n = int(eval(input()))
ls = [(0,0,0)]
for _ in range(n):
    a,b,c=list(map(int, input().split()))
    ls.append((a,b,c))

dpa = [0]*(n+1)
dpb = [0]*(n+1)
dpc = [0]*(n+1)

for x in range(1,n+1):
    a,b,c = ls[x]
    dpa[x] = max(dpc[x-1]+a,dpb[x-1]+a)
    dpb[x] = max(dpa[x-1]+b,dpc[x-1]+b)
    dpc[x] = max(dpa[x-1]+c,dpb[x-1]+c)


print((max(dpa[-1],dpb[-1],dpc[-1])))


# Optimized solution
n = int(eval(input()))
ls = [(0,0,0)]
for _ in range(n):
    a,b,c=list(map(int, input().split()))
    ls.append((a,b,c))

dpa = 0
dpb = 0
dpc = 0

for x in range(1,n+1):
    a,b,c = ls[x]
    dpa, dpb, dpc = max(dpc+a,dpb+a), max(dpa+b,dpc+b), max(dpa+c,dpb+c)


print((max(dpa,dpb,dpc)))
# Original solution
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[-inf]*3 for j in range(N+1)]
dp[0][0]=0
dp[0][1]=0
dp[0][2]=0

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    for i in range(3):
        if (m == i):
            continue
        dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)

# Optimized solution
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    if dp[n][m]>0:
        return dp[n][m]

    for i in range(3):
            if (i == m):
                continue
            dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)
# Original solution
N = int(eval(input()))
a = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*3 for _ in range(100010)] 
# dp[i][j] : i日目にj番目の活動をしたときの幸福度の総和
idx = [[1,2],[2,0],[0,1]]

for i in range(3):
    dp[0][i] = a[0][i]
    
for i in range(1,N):
    for j in range(3):
        dp[i][j] = max(dp[i-1][idx[j][0]],dp[i-1][idx[j][1]])+a[i][j]
    
print((max(dp[N-1])))

# Optimized solution
import sys
def input():
    return sys.stdin.readline()[:-1]

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

inf = 10**9+7
dp = [[0] * 3 for _ in range(N+10)]
dp[0] = [ABC[0][0],ABC[0][1],ABC[0][2]]

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][:])))
# Original solution
import sys
def input():
    return sys.stdin.readline()[:-1]

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

inf = 10**9+7
dp = [[0] * 3 for _ in range(N+10)]
dp[0] = [ABC[0][0],ABC[0][1],ABC[0][2]]

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][:])))


# Optimized solution

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

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

dp = [[0]*3 for _ in range(N+10)]
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][j])

print((max(dp[N])))
# Original solution
import sys
sys.setrecursionlimit(10 ** 6)

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


def recur(i, last_index, v):
    if i == n:
        return v
    res = -1
    for j in range(3):
        if j == last_index:
            continue
        res = max(res, recur(i + 1, j, v + abc[i][j]))
    return res


print((recur(0, -1, 0)))


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

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):
    dp[i][0] = abc[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = abc[i][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = abc[i][2] + max(dp[i-1][0], dp[i-1][1])
print((max(dp[-1])))
# Original solution
"C Vacation"
N = int(eval(input()))
summer = []
for i in range(N):
    active = list(map(int, input().split()))
    summer.append(active)

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

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

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


# Optimized solution
N = int(eval(input()))
S = [list(map(int, input().split())) for _ in range(N)]  # N日間の夏休み

dp = [[0]*3 for _ in range(N)]  # i日目の状態, (幸福度の合計, 前日の遊んだ内容3種類のテーブル)

# print(S)
# print(dp)

# 初期値
dp[0][0] = (S[0][0], 'a')
dp[0][1] = (S[0][1], 'b')
dp[0][2] = (S[0][2], 'c')

# print(dp)
for i in range(1, N):  # N日間の遷移
    # aの予定を実行する場合
    if dp[i-1][1][0]+S[i][0] > dp[i-1][2][0]+S[i][0]:
        dp[i][0] = (dp[i-1][1][0]+S[i][0], 'a')
    else:
        dp[i][0] = (dp[i-1][2][0]+S[i][0], 'a')

    # bの予定を実行する場合
    if dp[i-1][0][0]+S[i][1] > dp[i-1][2][0]+S[i][1]:
        dp[i][1] = (dp[i-1][0][0]+S[i][1], 'b')
    else:
        dp[i][1] = (dp[i-1][2][0]+S[i][1], 'b')

    # cの予定を実行する場合
    if dp[i-1][0][0]+S[i][2] > dp[i-1][1][0]+S[i][2]:
        dp[i][2] = (dp[i-1][0][0]+S[i][2], 'c')
    else:
        dp[i][2] = (dp[i-1][1][0]+S[i][2], 'c')

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

prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = list(map(int, input().split()))
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1

print((max(prev)))

# Optimized solution
import sys
# read = sys.stdin.read
input = sys.stdin.readline
# readlines = sys.stdin.readlines
days = int(eval(input()))

prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = list(map(int, input().split()))
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1

print((max(prev)))
# Original solution
#c
n=int(eval(input()))
N=100100
happy=[[0]*3 for i in range(N)]
dp=[[0]*3 for i in range(N)]
for i in range(1,n+1):
    x,y,z=list(map(int,input().split()))
    happy[i][0]=x
    happy[i][1]=y
    happy[i][2]=z
ans=0
for i in range(1,n+1):
    for place in range(3):
        for place_y in range(3):
            if place==place_y:
                continue
            else:
                dp[i][place]=max(dp[i][place],dp[i-1][place_y]+happy[i][place])

for place in range(3):
    ans=max(ans,dp[n][place])
print(ans)


# Optimized solution
n=int(eval(input()))
x=[[0]*3 for i in range(n)]

for i in range(n):
    a,b,c=list(map(int,input().split()))
    if i==0:
        x[i][0]=a 
        x[i][1]=b
        x[i][2]=c 
    else:
        x[i][0]=max(x[i-1][1],x[i-1][2])+a
        x[i][1]=max(x[i-1][0],x[i-1][2])+b
        x[i][2]=max(x[i-1][0],x[i-1][1])+c
    
print((max(x[n-1])))
# Original solution
n=int(eval(input()))
k=3
l=[]
for _ in range(n):
    l.append(list(map(int,input().split())))
dp=[l[0]]
for i,s in enumerate(l):
    if not i:continue
    t=[t for t in dp[-1]]
    d=[]
    for i in range(k):
        d.append(max(t[j]for j in range(k)if i!=j)+s[i])
    dp.append(d)
print((max(dp[-1])))

# Optimized solution
n=int(eval(input()))
l=[list(map(int,input().split()))for _ in[0]*n]
dp=l[0]
for i,s in enumerate(l):
    if not i:continue
    d=[]
    for i,t in enumerate(s):
        d.append(max(t for j,t in enumerate(dp)if i!=j)+t)
    dp=d
print((max(dp)))
# Original solution
N=int(eval(input()))
l1=[[] for i in range(N)]
for i in range(N):
    l=list(map(int,input().split()))
    for j in range(len(l)):
        l1[i].append(l[j])
pos=-1
f=-1
suma=0
for i in range(N):
    f=i
    if l1[i][0]>=l1[i][1] and l1[i][0]>=l1[i][2]:
        s=l1[i][0]
       # print(s)
        pos=0
    elif l1[i][1]>=l1[i][0] and l1[i][1]>=l1[i][2]:
        s=l1[i][1]
       # print(s)
        pos=1
    else:
        s=l1[i][2]
       # print(s)
        pos=2
    m=pos
    for j in range(i-1,-1,-1):
        if m==0:
            if l1[j][1]>=l1[j][2]:
                s=s+l1[j][1]
                #print(l1[j][1])
                m=1
            else:
                s=s+l1[j][2]
                #print(l1[j][2])
                m=2
        elif m==1:
            if l1[j][0]>=l1[j][2]:
                s=s+l1[j][0]
                #print(l1[j][0])
                m=0
            else:
                s=s+l1[j][2]
                #print(l1[j][2])
                m=2
        else:
            if l1[j][0]>=l1[j][1]:
                s=s+l1[j][0]
                #print(l1[j][0])
                m=0
            else:
                s=s+l1[j][1]
                #print(l1[j][1])
                m=1
    if suma<s:
        suma=s
    for j in range(i+1,N):
        if pos==0:
            if l1[j][1]>=l1[j][2]:
                s=s+l1[j][1]
                #print(l1[j][1])
                pos=1
            else:
                s=s+l1[j][2]
                #print(l1[j][2])
                pos=2
        elif pos==1:
            if l1[j][0]>=l1[j][2]:
                s=s+l1[j][0]
                #print(l1[j][0])
                pos=0
            else:
                s=s+l1[j][2]
                #print(l1[j][2])
                pos=2
        else:
            if l1[j][0]>=l1[j][1]:
                s=s+l1[j][0]
                #print(l1[j][0])
                pos=0
            else:
                s=s+l1[j][1]
                #print(l1[j][1])
                pos=1
    #print(s)
    if suma<s:
        suma=s
print(suma)


# Optimized solution
N=int(eval(input()))
l1=[[] for i in range(N)]
for i in range(N):
    l=list(map(int,input().split()))
    for j in range(len(l)):
        l1[i].append(l[j])
l2=[[] for i in range(N)]
for j in l1[0]:
    l2[0].append(j)
for j in range(1,N):
    l2[j].append(l1[j][0]+max(l2[j-1][1],l2[j-1][2]))
    l2[j].append(l1[j][1]+max(l2[j-1][0],l2[j-1][2]))
    l2[j].append(l1[j][2]+max(l2[j-1][0],l2[j-1][1]))
#print(l2)
print((max(l2[N-1][0],l2[N-1][1],l2[N-1][2])))
# Original solution
N = int(eval(input()))
dp = [[0]*3 for i 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
print((max(dp[N-1])))

# Optimized solution
import sys
readline = sys.stdin.readline
N = int(readline())
dp = [[0]*3 for i in range(N)]
dp[0] = list(map(int,readline().split()))
for i in range(1,N):
    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][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
readline = sys.stdin.readline
N = int(readline())
dp = [[0]*3 for i in range(N)]
dp[0] = list(map(int,readline().split()))
for i in range(1,N):
    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][0],dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c
print((max(dp[N-1])))


# Optimized solution
import sys
readline = sys.stdin.readline
N = int(readline())
dp = [[0,0,0] for i in range(N)]
dp[0] = list(map(int,readline().split()))
for i in range(1,N):
    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][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


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    dp = [[0] * 3 for _ in range(n)]
    for i in range(n):
        a, b, c = list(map(int, input().rstrip('\n').split()))
        if i == 0:
            dp[i][0] = a
            dp[i][1] = b
            dp[i][2] = c
        else:
            dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a)
            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][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)
            dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c)
    print((max(dp[-1])))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    dp = [[0] * 3 for _ in range(n)]
    for i in range(n):
        a, b, c = list(map(int, readline().split()))
        if i == 0:
            dp[i][0] = a
            dp[i][1] = b
            dp[i][2] = c
        else:
            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])))


if __name__ == '__main__':
    solve()
# Original solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    dp = [[0] * 3 for _ in range(n)]
    for i in range(n):
        a, b, c = list(map(int, readline().split()))
        if i == 0:
            dp[i][0] = a
            dp[i][1] = b
            dp[i][2] = c
        else:
            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])))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [0] * n
    b = [0] * n
    c = [0] * n
    for i in range(n):
        av, bv, cv = list(map(int, readline().split()))
        if i == 0:
            a[i] = av
            b[i] = bv
            c[i] = cv
        else:
            a[i] = max(b[i-1] + av, c[i-1] + av)
            b[i] = max(a[i-1] + bv, c[i-1] + bv)
            c[i] = max(a[i-1] + cv, b[i-1] + cv)
    print((max(a[-1], b[-1], c[-1])))


if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))

days=[]
dp = [0]*3
for _ in range(n):
  a = list(map(int,input().split()))
  days.append(a)

for i in range(3):
  dp[i]=days[0][i]
  
#rint(dp)
for cday in range(1,n):
  pday = cday-1
  t = [0]*3
  for i in range(3):
    max_val = dp[i]
    for j in range(3):
      if i!=j:
        cur_val = dp[j] + days[cday][i]
        if cur_val>max_val:
          max_val=cur_val
    
    t[i] = max_val
  dp=t
  #rint(dp)
  	
print((max(dp)))
  
  

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


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*3

for i in range(3):
  dp[i]= days[0][i]
#print(dp) 
for cur_day in range(1,n):
  m = [0]*3
  for i in range(3):
    for j in range(3):
      if i!=j:
        m[i] = max(m[i],dp[j]+days[cur_day][i])
  dp = m
#  print(dp)
  
print((max(dp)))
# Original solution
#import
#import math
#import numpy as np
N = int(eval(input()))
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

a = []

# dp[i][0]:Aを選んだ  dp[i][1]:Bを選んだ  dp[i][2]:Cを選んだ 

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

for _ in range(N):
    aa = list(map(int, input().split()))
    a.append(aa)

for i in range(1, N+1):
    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-1][k])

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

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

#import
#import math
#import numpy as np
N = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(N)]

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

for i in range(N):
    if i == 0:
        dp[i][0] = abc[i][0]
        dp[i][1] = abc[i][1]
        dp[i][2] = abc[i][2]
        continue

    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])



print((max(dp[-1])))
# Original solution
N = int(eval(input()))
src = [tuple(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] + src[i][k])
print((max(dp[-1])))

# Optimized solution
N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]

dp = [[0]*3 for i in range(N)]
dp[0] = src[0]
for i,(a,b,c) in enumerate(src[1:]):
    dp[i+1][0] = a + max(dp[i][1], dp[i][2])
    dp[i+1][1] = b + max(dp[i][2], dp[i][0])
    dp[i+1][2] = c + max(dp[i][0], dp[i][1])
print((max(dp[-1])))
# Original solution
import copy

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

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

for i, l in enumerate(abc):
    if i == 0:
        dp[i] = copy.deepcopy(l)
    else:
        mx = 0
        ex = [0, 1, 2]
        ext = copy.deepcopy(ex)
        for j, m in enumerate(l):
            ext.remove(j)
            mx1 = max(mx, abc[i][ext[0]] + dp[i - 1][j])
            mx2 = max(mx, abc[i][ext[1]] + dp[i - 1][j])
            mx = max(mx1, mx2)
            ext = copy.deepcopy(ex)
            dp[i][j] = mx

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

# Optimized solution
N = int(eval(input()))
la, lb, lc = [0] * 3

for i in range(N):
    a, b, c = [int(x) for x in input().split()]
    aa = a + max(lb, lc)
    bb = b + max(lc, la)
    cc = c + max(lb, la)
    la = aa
    lb = bb
    lc = cc

print((max(la, lb, lc)))
# Original solution
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
A, B, C = [0]*N, [0]*N, [0]*N

for i in range(N):
    A[i], B[i], C[i] = inpl()

DP = [[0]*3 for _ in range(N)]
DP[0] = [A[0], B[0], C[0]]

for i in range(1, 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[-1])))

# Optimized solution
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
sa, sb, sc = 0, 0, 0
for i in range(N):
    a, b, c = inpl()
    sa, sb, sc = max(sb+a, sc+a), max(sa+b, sc+b), max(sa+c, sb+c)
print((max(sa, sb, sc)))
# Original solution
n=int(eval(input()))
mat=[]
dp=[]

for i in range(n):
    l=list(map(int,input().split()))
    mat.append(l)
    dp.append([0]*3)

dp[0][0]=mat[0][0]
dp[0][1]=mat[0][1]
dp[0][2]=mat[0][2]

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

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


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

for i in range(n):
    l=list(map(int,input().split()))
    mat.append(l)
    dp.append([0]*3)

dp[0][0]=mat[0][0]
dp[0][1]=mat[0][1]
dp[0][2]=mat[0][2]

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

print((max(dp[n-1])))
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a=[[0],[0],[0]]
n = int(eval(input()))
for i in range(n):
    A,B,C = list(map(int,input().split()))
    a[0].append(A)
    a[1].append(B)
    a[2].append(C)
dp = []
for j in range(n+1):
    dp.append([0,0,0])

dp[1][0] = a[0][1]
dp[1][1] = a[1][1]
dp[1][2] = a[2][1]
for i in range(2,n+1):
    for j in range(3):
        x = dp[i-1][(j+1)%3]+a[j][i]
        y = dp[i-1][(j+2)%3]+a[j][i]
        dp[i][j] = max(x,y)
print((max(dp[n][0],dp[n][1],dp[n][2])))


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,c = 0,0,0
n = int(eval(input()))
for i in range(n):
    x,y,z = list(map(int,input().split()))
    a,b,c = max(b,c)+x,max(a,c)+y,max(a,b)+z

print((max(a,b,c)))
# Original solution
from functools import lru_cache

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

@lru_cache(maxsize=1000000)
def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

import sys
sys.setrecursionlimit(1000000)
print((max([dp(n-1,a) for a in range(3)])))


# Optimized solution
from functools import lru_cache

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

@lru_cache(maxsize=None)
def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

import sys
sys.setrecursionlimit(1000000)
print((max([dp(n-1,a) for a in range(3)])))
# Original solution
def main():
    n = int(eval(input()))
    abc = [list(map(int,input().split())) for i 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(n-1):
        today = dp[i]
        tomorrow = abc[i+1]
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][j] = max(dp[i+1][j], today[k] + tomorrow[j])

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

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    abc = [list(map(int,input().split())) for i 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(n-1):
        for j in range(3):
            dp[i+1][j] = max(dp[i][(j+1) % 3], dp[i][(j+2) % 3]) + abc[i+1][j]

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

if __name__ == "__main__":
    main()