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

table = []
for _ in range(n):
    table.append([int(v) for v in input().split()])

dp = [0] * 3

for i in range(n):
    dp_n = [0] * 3

    a, b, c = table[i]

    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]

    dp_n[0] = max(b0, c0) + a
    dp_n[1] = max(c0, a0) + b
    dp_n[2] = max(a0, b0) + c

    dp = dp_n

print((max(dp)))


# Optimized solution
def main():
    N = int(eval(input()))

    table = []
    for _ in range(N):
        a, b, c = list(map(int, input().split()))
        table.append((a, b, c))

    dp = [0] * 3

    for i in range(N):
        a, b, c = table[i]

        a0 = dp[0]
        b0 = dp[1]
        c0 = dp[2]

        dp[0] = max(b0, c0) + a
        dp[1] = max(c0, a0) + b
        dp[2] = max(a0, b0) + c

    print((max(dp)))

main()
# Original solution
N = int(eval(input()))
vacation = []
for i in range(N):
    vacation.append(list(map(int, input().split())))

activities = 3
schedules = [[None for _ in range(activities)] for _ in range(N)]
schedules[0] = vacation[0]

for i in range(1, N):
    for j in range(activities):
        schedules[i][j] = max(schedules[i - 1][(j + 1) % 3], schedules[i - 1][(j + 2) % 3]) + vacation[i][j]

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

# Optimized solution
def main():
    n = int(eval(input()))
    matrix = []
    tb = [[0] * 4 for _ in range(n + 1)]
    for _ in range(n):
        matrix.append([int(e) for e in input().split()])
    
    for i in range(1, n + 1):
        for j in range(1, 4):
            for l in range(1, 4):
                if j == l: continue
                tb[i][j] = max(tb[i][j], tb[i - 1][l] + matrix[i - 1][j - 1])
    
    print((max(tb[n])))
    return 0

if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))

felicidade = []

for x in range(n):
    felicidade.append(list(map(int,input().split())))

DP = [0,0,0]

if n == 1:
    print((max(felicidade[0])))

else:

    for x in range(3):
        DP[x] = felicidade[0][x]


    for dia in range(1,n):
        m = [0] * 3
        for x  in range(3):#As duas possíveis escolhas são x e y
            for y  in range(3):
                if x != y: #Se elas forem diferentes
                    m[x] = max(m[x], DP[y] + felicidade[dia][x])
        DP = m
    
    print((max(DP)))


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

today = [int(x) for x in input().split()]

for i in range(nDays - 1):
    tomorrow = [int(x) for x in input().split()]
    tomorrow[0] += max(today[1], today[2])
    tomorrow[1] += max(today[0], today[2])
    tomorrow[2] += max(today[0], today[1])
    today = tomorrow

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

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

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

dp = [[0 for _ in range(3)] for _ in range(N+1)]
#dp[i][j]:i日目に活動a~cを行ったときに得られる最高の累積幸福度

for i in range(1, N+1):
    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][0], dp[i-1][2])
    dp[i][2] = c + max(dp[i-1][0], dp[i-1][1])

print((max(dp[-1][0], dp[-1][1], dp[-1][2])))
# Original solution
N = int(eval(input()))
A_B_C = []
for i in range(N):
    A_B_C.append(tuple(map(int, input().split())))

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

DP[0][0] = A_B_C[0][0]
DP[0][1] = A_B_C[0][1]
DP[0][2] = A_B_C[0][2]
for i in range(1, N):
    for j in range(3):
        j_a = (j + 1) % 3
        j_b = (j + 2) % 3
        DP[i][j] = max(DP[i-1][j_a], DP[i-1][j_b]) + A_B_C[i][j]

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

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

DP = [0] * 3

for f in F:
    D = [0] * 3
    S = {0, 1, 2}
    for i in range(3):
        S.remove(i)
        for s in S:
            D[i] = max(D[i], f[i] + DP[s])
        S.add(i)
    DP = D

print((max(DP)))
# Original solution
N = int(eval(input()))
ABC = []
for _ in range(N):
        a,b,c = list(map(int,input().split()))
        ABC.append((a,b,c))

dpA = [ABC[0][0]]*N
dpB = [ABC[0][1]]*N
dpC = [ABC[0][2]]*N

for i in range(1, N):
        dpA[i] = max(dpB[i-1] + ABC[i][0], dpC[i-1] + ABC[i][0])
        dpB[i] = max(dpA[i-1] + ABC[i][1], dpC[i-1] + ABC[i][1])
        dpC[i] = max(dpA[i-1] + ABC[i][2], dpB[i-1] + ABC[i][2])
print((max(dpA[N-1], dpB[N-1], dpC[N-1])))

# Optimized solution
N = int(eval(input()))
for i in range(N):
        a,b,c = list(map(int,input().split()))
        if i == 0:
                preA = a
                preB = b
                preC = c
        else:
                A = max(preB + a, preC + a)
                B = max(preA + b, preC + b)
                C = max(preA + c, preB + c)
                preA = A
                preB = B
                preC = C
print((max(preA, preB, preC)))
# 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()))
    a[i] = a[i] + max(b[i - 1], c[i - 1])
    b[i] = b[i] + max(c[i - 1], a[i - 1])
    c[i] = c[i] + max(a[i - 1], b[i - 1])
print((max(a[n], b[n], c[n])))

# Optimized solution
n = int(eval(input()))
hya, hyb, hyc = 0, 0, 0
for _ in range(n):
    a, b, c = list(map(int, input().split()))
    ha = a + max(hyb, hyc)
    hb = b + max(hyc, hya)
    hc = c + max(hya, hyb)
    hya =ha
    hyb =hb
    hyc =hc
print((max(ha, hb, hc)))
# Original solution
n=int(eval(input()))
a,b,c = list(map(int,input().split()))
d={'a':a,'b':b,'c':c}#初期化
for i in range(n-1):
    a,b,c = list(map(int,input().split()))
    da,db,dc=d['a'],d['b'],d['c']
    d['a'] = a +max(db,dc)
    d['b'] = b +max(da,dc)
    d['c'] = c +max(da,db)
print((max(d.values())))

# Optimized solution
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)
dpa,dpb,dpc = A[0],B[0],C[0]
for i in range(1,N):
    a,b,c = dpa,dpb,dpc
    dpa = max(c,b)+A[i]
    dpb = max(c,a)+B[i]
    dpc = max(a,b)+C[i]
print((max(dpa,dpb,dpc)))
# Original solution
n = int(eval(input()))

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

dp = [[float('-inf')] * 3 for _ in range(n)]

from copy import deepcopy

dp[0] = deepcopy(eff[0])

for i in range(1, n):
    for yi in range(3):
        for ti in range(3):
            if yi != ti:
                dp[i][ti] = max(dp[i][ti], dp[i-1][yi] + eff[i][ti])

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

# Optimized solution
from copy import deepcopy
n = int(eval(input()))
eff = [list(map(int, input().split())) for _ in range(n)]

dp = [[float('-inf')] * 3 for _ in range(n)]

dp[0] = deepcopy(eff[0])

for i in range(1, n):
    for yi in range(3):
        for ti in range(3):
            if yi != ti:
                dp[i][ti] = max(dp[i][ti], dp[i-1][yi] + eff[i][ti])

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

dp = [[float('-inf')] * 3 for _ in range(n)]

dp[0] = deepcopy(eff[0])

for i in range(1, n):
    for yi in range(3):
        for ti in range(3):
            if yi != ti:
                dp[i][ti] = max(dp[i][ti], dp[i-1][yi] + eff[i][ti])

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

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

da = db = dc = 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)))
# Original solution
# coding: utf-8
# import sys
# input = sys.stdin.readline

def dp_happiness(N):
    yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
    for _ in range(N):
        a, b, c = list(map(int, input().split()))

        today_a = a + max(yesterday_b, yesterday_c)
        today_b = b + max(yesterday_c, yesterday_a)
        today_c = c + max(yesterday_a, yesterday_b)

        yesterday_a = today_a
        yesterday_b = today_b
        yesterday_c = today_c
    return max(today_a, today_b, today_c)

N = int(eval(input()))
print((dp_happiness(N)))

# Optimized solution
# coding: utf-8
import sys
input = sys.stdin.readline

def dp_happiness(N):
    yesterday_a, yesterday_b, yesterday_c = 0, 0, 0
    for _ in range(N):
        a, b, c = list(map(int, input().split()))

        today_a = a + max(yesterday_b, yesterday_c)
        today_b = b + max(yesterday_c, yesterday_a)
        today_c = c + max(yesterday_a, yesterday_b)

        yesterday_a = today_a
        yesterday_b = today_b
        yesterday_c = today_c
    return max(today_a, today_b, today_c)

N = int(eval(input()))
print((dp_happiness(N)))
# Original solution
n = int(eval(input()))
a = ([list(map(int, input().split())) for _ in range(n)])
a.insert(0,[0,0,0])

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

for i, a in enumerate(a):
  dp_1 = dp[i-1]
  dp[i][0] = max(dp_1[1], dp_1[2]) + a[0]
  dp[i][1] = max(dp_1[0], dp_1[2]) + a[1]
  dp[i][2] = max(dp_1[0], dp_1[1]) + a[2]

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


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

if __name__ == '__main__':
    main()
# Original solution
def main():
    n = int(eval(input()))
    abc = []
    for _ in range(n):
        abc.append(tuple(map(int, input().split())))
    dp = [[0,0,0] 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):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + abc[i][0]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + abc[i][1]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + abc[i][2]
    print((max(dp[n-1])))

if __name__ == '__main__':
    main()

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

def main():
    n = int(eval(input()))
    colA, colB, colC = list(map(int, input().split()))
    for i1 in range(1, n):
        a, b, c = list(map(int, input().split()))
        colA, colB, colC = a + max(colB, colC), b + max(colA, colC), c + max(colA, colB)
    print((max(colA, colB, colC)))

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

def main():
    N = int(eval(input()))
    a1,b1,c1 = 0,0,0
    for _ in range(N):
        a,b,c = list(map(int, input().split()))
        a0,b0,c0 = a1,b1,c1
        a1 = max(b0, c0) + a # b or c => a
        b1 = max(a0, c0) + b # a or c => b
        c1 = max(a0, b0) + c # a or b => c

    print((max(a1,b1,c1)))

if __name__ == '__main__':
    main()


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

def main():
    N = int(eval(input()))
    a1,b1,c1 = 0,0,0
    for _ in range(N):
        a,b,c = list(map(int, input().split()))
        a0,b0,c0 = a1,b1,c1
        a1 = a + (b0 if b0 > c0 else c0)
        b1 = b + (a0 if a0 > c0 else c0)
        c1 = c + (a0 if a0 > b0 else b0)

    print((max(a1,b1,c1)))

if __name__ == '__main__':
    main()
# Original solution
# EduDPC - Vacation
import sys
input = sys.stdin.readline

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

# Optimized solution
# dpC - Vacation
# 貰うDP
import sys
input = sys.stdin.readline

def main():
    n = int(eval(input()))
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    dp = [[0] * 3 for _ in range(n)]
    dp[0] = A[0]
    for i in range(1, n):  # i-th day
        for j in range(3):  # yesterday
            for k in range(3):  # today
                if j != k:
                    dp[i][k] = max(dp[i][k], dp[i - 1][j] + A[i][k])
    print((max(dp[-1])))


if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N)]

dp[0][0], dp[0][1], dp[0][2] = list(map(int, input().split()))
for i in range(1,N):
  abc = list(map(int, input().split()))
  for j,k,l in ((0,1,2), (1,0,2), (2, 0, 1)):
    dp[i][j] = abc[j] + max(dp[i-1][k], dp[i-1][l])

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

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

x, y, z = list(map(int, input().split()))
for _ in range(N-1):
  a, b, c = list(map(int, input().split()))
  x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)

print((max(x,y,z)))
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
    a.append([0,0,0])
    a[i][0],a[i][1],a[i][2]=list(map(int,input().split()))
a.reverse()
b=[a[0][0],a[0][1],a[0][2]]
for i in range(1,n):
    b1=b[:]
    b[0]=max(a[i][0]+b1[1],a[i][0]+b1[2])
    b[1]=max(a[i][1]+b1[0],a[i][1]+b1[2])
    b[2]=max(a[i][2]+b1[1],a[i][2]+b1[0])
print((max(b)))



# Optimized solution
n=int(eval(input()))
a=[]
for i in range(n):
    a.append([0,0,0])
    a[i][0],a[i][1],a[i][2]=list(map(int,input().split()))
b=[a[0][0],a[0][1],a[0][2]]
for i in range(1,n):
    b1=b[:]
    b[0]=max(a[i][0]+b1[1],a[i][0]+b1[2])
    b[1]=max(a[i][1]+b1[0],a[i][1]+b1[2])
    b[2]=max(a[i][2]+b1[1],a[i][2]+b1[0])
print((max(b)))
# Original solution
N = int(eval(input()))
happy_list = [list(map(int, input().split())) for n in range(N)]
def chmax(a, b):
    if a > b:
        return a
    else:
        return b
dp_list = [[0, 0, 0]]
for n in range(1, N+1):
    tmp = [0, 0, 0]
    tmp[1] = chmax(tmp[1], dp_list[n-1][0] + happy_list[n-1][1])
    tmp[2] = chmax(tmp[2], dp_list[n-1][0] + happy_list[n-1][2])
    tmp[0] = chmax(tmp[0], dp_list[n-1][1] + happy_list[n-1][0])
    tmp[2] = chmax(tmp[2], dp_list[n-1][1] + happy_list[n-1][2])
    tmp[0] = chmax(tmp[0], dp_list[n-1][2] + happy_list[n-1][0])
    tmp[1] = chmax(tmp[1], dp_list[n-1][2] + happy_list[n-1][1])
    dp_list.append(tmp)
print((max(tmp)))

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

happy_list = [[0, 0, 0]] # n日目にa|b|cを選んだときの幸福のそこまでの最大値
# before_act = -1 # a: 0, b: 1, c: 2
for n in range(N):
    before_happy_a, before_happy_b, before_happy_c = happy_list[-1]
    a, b, c = abc_list[n]
    tmp_happy_a = max(before_happy_b, before_happy_c) + a
    tmp_happy_b = max(before_happy_c, before_happy_a) + b
    tmp_happy_c = max(before_happy_a, before_happy_b) + c
    happy_list.append([tmp_happy_a, tmp_happy_b, tmp_happy_c])

print((max(happy_list[-1])))
# 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[0] = [a[0], b[0], c[0]]

for i in range(N - 1):
    dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
    dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
    dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
    
print((max(dp[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()))

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(a[i]+dp[i-1][1],a[i]+dp[i-1][2])
    dp[i][1]=max(b[i]+dp[i-1][0],b[i]+dp[i-1][2])
    dp[i][2]=max(c[i]+dp[i-1][0],c[i]+dp[i-1][1])
print((max(dp[-1])))
# Original solution
N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]

dp = [[0 for i in range(3)] for j 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]+l[i-1][k])

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



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

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

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

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

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

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

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

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

for i in range(N):
  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]+A[i][j])

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

# Optimized solution
def main():
    n, *abc = list(map(int, open(0).read().split()))
    dp = [[0, 0, 0] for _ in range(n + 1)]
    for i, (a, b, c) in enumerate(zip(abc[::3], abc[1::3], abc[2::3]), 1):
        x, y, z = dp[i - 1]
        dp[i] = [a + max(y, z), b + max(z, x), c + max(x, y)]

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


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
dp = [[0 for _ in range(3)] for _ in range(n+1)]
ls  = [[1,2],[0,2],[0,1]]
for i in range(1,n+1):
    day = list(map(int,input().split()))
    dp[i][0] = day[0] + max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = day[1] + max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = day[2] + max(dp[i-1][0],dp[i-1][1])
print((max(dp[n])))


# Optimized solution
N = int(eval(input()))
ls = [[0 for i in range(3)] for i in range(N)]
for i in range(N):
    ls[i] = list(map(int,input().split()))
# dp[i][j] -> i-1日目にjの仕事をしたときの i 日目の幸福度の総和
dp = [ [0 for i in range(3)] for i in range(N)]
for i in range(3):
    dp[0][i] = ls[0][i]
for i in range(1,N):
    for j in range(3):
        w = [0,1,2]
        w.remove(j)
        x,y = w[0],w[1]
        dp[i][j] = max(dp[i-1][x],dp[i-1][y]) + ls[i][j]
            
print((max(dp[N-1])))
# Original solution
N = int(eval(input()))
act = list(list(map(int, input().split())) for _ in range(N))
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
  dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2]))
  dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2]))
  dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1]))
print((max(dp[N])))

# Optimized solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
act = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[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]) + act[i + 1][j]
print((max(dp[-1])))
# Original solution
n=int(eval(input()))
a=[[]]
for i in range(n):
    a.append([int(i) for i in input().split()])
dp=[[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
            dp[i][j]=a[i][j]+max(dp[i-1][k] for k in range(3) if k!=j)
print((max(dp[n])))

# Optimized solution
n=int(eval(input()))
lst=[]
for i in range(n):
    lst.append([int(i) for i in input().split()])
dp=[[0,0,0] for i in range(n)]
dp[0]=lst[0]

for i in range(1,n):
    for j in range(3):
        dp[i][j]=lst[i][j]+max(dp[i-1][k] for k in range(3) if k!=j)
print((max(dp[n-1])))
# Original solution
import sys
sys.setrecursionlimit(1000000)

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

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

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

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

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


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

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

def summerVacation(n, i):
  if n ==0:
    dp[n][i] = a[n][i]
    return
  i1 = (i+1) % 3
  i2 = (i+2) % 3  
  dp[n][i] = max( dp[n-1][i1], dp[n-1][i2] ) + a[n][i]  
  
dp =[[None]*3 for _ in range(N)]
for n in range(N):
  for i in range(3):
    summerVacation(n, i)
    
print(( max( dp[N-1][0], dp[N-1][1], dp[N-1][2] )))
# Original solution
n = int(eval(input()))
a = [0]
b = [0]
c = [0]

for i in range(n):
    aa,bb,cc = list(map(int,input().split()))
    a.append(max(b[i] + aa, c[i] + aa))
    b.append(max(a[i] + bb, c[i] + bb))
    c.append(max(a[i] + cc, b[i] + cc))
    
print((max(a[-1], b[-1], c[-1])))


# Optimized solution
def main():
  n = int(eval(input()))
  a = [0]
  b = [0]
  c = [0]

  for i in range(n):
      aa,bb,cc = list(map(int,input().split()))
      a.append(max(b[i] + aa, c[i] + aa))
      b.append(max(a[i] + bb, c[i] + bb))
      c.append(max(a[i] + cc, b[i] + cc))

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

main()
# Original solution
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 6)

N = int(eval(input()))

plans = []

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

  
@lru_cache(maxsize=None)
def max_utility_at(day, i):
  candidates = [
    (1, 2),
    (0, 2),
    (0, 1)
  ]
  if day == 0:
    return plans[0][i]
  else:    
    return max(max_utility_at(day - 1, x) + plans[day][i] for x in candidates[i])

  
print((max(max_utility_at(N - 1, x) for x in (0, 1, 2))))

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

plans = []

for _ in range(N):
  a, b, c = list(map(int, input().split()))
  plans.append((a, b, c))
  
memo = [[0] * (N + 1) for _ in range(3)]

for day, plan in enumerate(plans, 1):
  memo[0][day] = max(memo[1][day - 1], memo[2][day - 1]) + plan[0]
  memo[1][day] = max(memo[0][day - 1], memo[2][day - 1]) + plan[1]
  memo[2][day] = max(memo[0][day - 1], memo[1][day - 1]) + plan[2]
    
print((max(memo[0][N], memo[1][N], memo[2][N])))
# Original solution
#!/usr/bin/env python3
#dp3 #Vacation
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[-1],dpb[-1],dpc[-1])))


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

def c():
    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[-1],dpb[-1],dpc[-1])))
if __name__ == '__main__':
    c()
# Original solution
n = int(eval(input()))
a_ls = [0] * n
b_ls = [0] * n
c_ls = [0] * n
for i in range(n):
    a,b,c = list(map(int,input().split()))
    a_ls[i] = a
    b_ls[i] = b
    c_ls[i] = c

dp = [[0]*3 for _ in range(n+1)]
dp[1] = [a_ls[0], b_ls[0], c_ls[0]]
for i in range(1,n):
    dp[i+1][0] = max(dp[i+1][0], dp[i][1] + a_ls[i], dp[i][2] + a_ls[i])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0] + b_ls[i], dp[i][2] + b_ls[i])
    dp[i+1][2] = max(dp[i+1][2], dp[i][0] + c_ls[i], dp[i][1] + c_ls[i])

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

# Optimized solution
n = int(eval(input()))
days_ls = [0] * n
for i in range(n):
    days_ls[i] = list(map(int, input().split()))

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