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

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

print((max(a, b, c)))

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

x, y, z = 0, 0, 0
for a, b, c in h:
    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 _ in range(n)]

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

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

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

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

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

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

ans = max(dp[-1])
print(ans)
# Original solution
N = int(eval(input()))
Y = []
for _ in range(N):
    Y.append(list(map(int, input().split())))  # Y = [[3, 9, 7], [10, 3, 2]]
dp = [[0] * 3 for _ in range(N)]  # 初期化
dp[0] = Y[0]  # 初期化

# A, B, C の3パターン以外にも対応
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] + Y[i+1][j])
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)]  # 初期化　[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] for n = 4
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])))
# Original solution
def main():
    import sys
    input = sys.stdin.readline

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

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

    dp[0] = ABC[0]
    ind = [[1, 2], [0, 2], [0, 1]]
    for i in range(1, N):
        a, b, c = ABC[i]

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


if __name__ == "__main__":
    main()


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

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

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

    for i in range(N-1):
        a, b, c = ABC[i+1]

        dp[i+1][0] = a + max(dp[i][1], dp[i][2])
        dp[i+1][1] = b + max(dp[i][0], dp[i][2])
        dp[i+1][2] = c + max(dp[i][0], dp[i][1])

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


if __name__ == "__main__":
    main()
# Original solution
import sys
#import unittest
#import collections

def plan_vacation(activity, n):
	dp = [[0] * 3 for i in range(n)]
	for i in range(3):
		dp[0][i] = activity[0][i]
	
	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] + activity[i][j])
	return max(dp[n-1])
	
	
def read_input():
	#Read the input N
	n = int(sys.stdin.readline())
	activity = [[0]* 3 for i in range(n)]
	for i in range(n):
		a = sys.stdin.readline().split()
		for j in range(3):
			activity[i][j] = int(a[j])
	
	result = plan_vacation(activity, n)
	print(result)
		
if __name__ == '__main__':
	 read_input()


# Optimized solution
import sys
#import unittest
#import collections

def plan_vacation(activity, n):
	dp = [0] * 3 
	for i in range(3):
		dp[i] = activity[0][i]
	
	for i in range(1, n):
		new_dp = [0] * 3
		for j in range(3):
			for k in range(3):
				if j != k:
					new_dp[j] = max(new_dp[j], dp[k] + activity[i][j])
		dp = new_dp
	return max(dp)
	
	
def read_input():
	#Read the input N
	n = int(sys.stdin.readline())
	activity = [[0]* 3 for i in range(n)]
	for i in range(n):
		a = sys.stdin.readline().split()
		for j in range(3):
			activity[i][j] = int(a[j])
	
	result = plan_vacation(activity, n)
	print(result)
		
if __name__ == '__main__':
	 read_input()
# Original solution
s = list(map(int, input().split()))
n=s[0]
dp=[[0]*3 for i in range(n)]
s = list(map(int, input().split()))
dp[0][0]=s[0]
dp[0][1] = s[1]
dp[0][2] = s[2]
for i in range(1,n):
    s = list(map(int, input().split()))
    dp[i][0] = max(dp[i-1][1]+s[0], dp[i-1][2]+s[0])
    dp[i][1] = max(dp[i-1][0]+s[1], dp[i-1][2]+s[1])
    dp[i][2] = max(dp[i-1][0]+s[2], dp[i-1][1]+s[2])
print((max(dp[n-1])))

# Optimized solution

n=list(map(int,input().split()))[0]

dp=[[0]*3 for _ 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][1]+c,dp[i-1][0]+c)
print((max(dp[-1])))
# Original solution
n=int(eval(input()))
l1=[]
l2=[]
l3=[]
for i in range(n):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	w=int(l[2])
	l1.append(u)
	l2.append(v)
	l3.append(w)
dpu=[0 for i in range(n)]
dpv=[0 for i in range(n)]
dpw=[0 for i in range(n)]
dpu[0]=l1[0]
dpv[0]=l2[0]
dpw[0]=l3[0]
for i in range(1,n):
	dpu[i]=max(dpv[i-1],dpw[i-1])+l1[i]
	dpv[i]=max(dpu[i-1],dpw[i-1])+l2[i]
	dpw[i]=max(dpu[i-1],dpv[i-1])+l3[i]
print((max(dpu[-1],dpv[-1],dpw[-1])))


# Optimized solution
n=int(eval(input()))
l=[]
for i in range(n):
    lo=input().split()
    l.append((int(lo[0]),int(lo[1]),int(lo[2])))
dp=[[0 for i in range(3)]for i in range(n)]
dp[0][0]=l[0][0]
dp[0][1]=l[0][1]
dp[0][2]=l[0][2]
for i in range(1,n):
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+l[i][0]
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+l[i][1]
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+l[i][2]
print((max(dp[n-1][0],dp[n-1][1],dp[n-1][2])))
# Original solution
import sys
sys.setrecursionlimit(int(1e6))

n=int(eval(input()))
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print((max(dp(n,0),dp(n,1),dp(n,2))))

# Optimized solution
import sys
sys.setrecursionlimit(int(1e6))

n=int(eval(input()))
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
s1=dp(n,0)
s2=dp(n,1)
s3=dp(n,2)
print((max(s1,s2,s3)))
# Original solution
def main():
    n = int(eval(input()))
    x = []
    for _ in range(n):
        a, b, c = list(map(int, input().split()))
        x.append([a, b, c])
    dp = [[0] * 3 for _ in range(n)]
    # i日目の幸福度dp[i-1]
    # まず1日目の幸福度を設定
    dp[0] = [x[0][l] for l in range(3)]
    for i in range(1,n):
        for j in range(3):
            dp[i][j] = max([dp[i-1][k]+x[i][j] for k in range(3) if k != j]+[dp[i][j]])
    print((max(dp[n-1])))

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    x = []
    for _ in range(n):
        a, b, c = list(map(int, input().split()))
        x.append((a, b, c))
    dp0 = [0]*(n+1)
    dp1 = [0]*(n+1)
    dp2 = [0]*(n+1)
    for i in range(1,n+1):
        a, b, c = x[i-1]
        dp0[i] = max(dp1[i-1]+a, dp2[i-1]+a)
        dp1[i] = max(dp0[i-1]+b, dp2[i-1]+b)
        dp2[i] = max(dp0[i-1]+c, dp1[i-1]+c)
    print((max(dp0[n], dp1[n], dp2[n])))

if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
a,b,c = list(map(int,input().split()))
dp = [0,0,0] * n
dp[0] = [a,b,c]
for i in range(1,n):
    a,b,c = list(map(int,input().split()))
    dp[i] = [max(dp[i-1][1],dp[i-1][2])+a,max(dp[i-1][0],dp[i-1][2])+b,max(dp[i-1][0],dp[i-1][1])+c]

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

# 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
N=int(eval(input()))
dp=[[0]*3 for i in range(N+1)]
for i in range(1,N+1):
  a=list(map(int,input().split()))
  for j in range(3):
    tmp=[]
    for k in range(3):
      if j!=k:
        dp[i][k]=max(dp[i][k],dp[i-1][j]+a[k])  
print((max(dp[-1])))

# Optimized 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(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])))
# 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(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
import sys
input = sys.stdin.readline
N = int(eval(input()))
table = []
dp = [[0]*3 for i in range(N)]

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

dp[0] = table[0]
for i in range(1,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]+table[i][j])
print((max(dp[-1])))
# Original solution
n= int(eval(input()))
active = [[0, 0, 0]] * n

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

dp = [[]] * (n + 1)
for i in range(n+1):
  dp[i] = [0, 0, 0]

#print(n, active, dp)

def chmin(arr, index_a, val):
  if arr[index_a] > val:
    arr[index_a] = val
    return True
  return False

def chmax(arr, index_a, val):
  if arr[index_a] < val:
    arr[index_a] = val
    return True
  return False

ans = 0
pre_active = None
for i in range(n):
  a, b, c = active[i]
  dp_i = i + 1 # dpの添字はi日目なので、i = 0 = 初期状態, この場合 i が前日になる
  
  # i日目に a を選ぶ
  dp[dp_i][0] = max(dp[i][1] + a, dp[i][2] + a)
  # i日目に b を選ぶ
  dp[dp_i][1] = max(dp[i][0] + b, dp[i][2] + b)
  # i日目に a を選ぶ
  dp[dp_i][2] = max(dp[i][0] + c, dp[i][1] + c)

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

# 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 = [[]] * (n+1)
for i in range(n+1):
  dp[i] = [0, 0, 0]

for i in range(n):
  dp[i+1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i])
  dp[i+1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i])
  dp[i+1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i])
print((max(dp[n])))
# Original solution
import sys
 
 
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
 
 
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
 
 
def input(): return sys.stdin.readline().strip()
 
 
def maxim(i, char):
    if i < 0:
        return 0
 
    if li[i][char] != -1:
        ##print('hi')
        ##print(i,char)
        return li[i][char]
    if char == 2:
        li[i][2] = max(c[i] + maxim(i - 1, 1), c[i] + maxim(i - 1, 0))
        return li[i][2]
    if char == 1:
        li[i][1] = max(b[i] + maxim(i - 1, 0), b[i] + maxim(i - 1, 2))
        return li[i][1]
    if char == 0:
        li[i][0] = max(a[i] + maxim(i - 1, 1), a[i] + maxim(i - 1, 2))
        return li[i][0]
    if char == 3:
        li[i][3] = (max(maxim(i - 1, 2), maxim(i - 1, 1), maxim(i - 1, 0)))
        return li[i][3]
 
 
n = int(eval(input()))
a, b, c = [], [], []
for _ in range(n):
    x, y, z = get_ints()
    li = [[-1 for i in range(4)] for j in range(n+1)]
    a.append(x)
    b.append(y)
    c.append(z)
li = [[-1 for i in range(4)] for j in range(n+1)]
print((maxim(n , 3)))

# Optimized solution
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()


n=int(eval(input()))
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    ##li=[[-1 for i in range(4)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(4)]for j in range(n)]
for i in range(n):
   for j in range(4):
        if i==0:
            if j==0:
                li[i][j]=a[i]
            if j==1:
                li[i][j]=b[i]
            if j==2:
                li[i][j]=c[i]
            if j==3:
                li[i][j] = 0
            continue
        if j==0:
            li[i][j] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])
        if j==1:
            li[i][j] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])
        if j==2:
            li[i][j] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
        if j==3:
            li[i][3] = (max(li[i - 1][2],li[i - 1][1], li[i - 1][0]))
print((max(li[n-1])))
# Original solution
n = int(eval(input()))

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


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

dp = [0 for i in range(3)]
for i in range(1,n+1):
    a,b,c = list(map(int, input().split()))
    x = max(dp[1] + a, dp[2] + a)
    y = max(dp[2] + b, dp[0] + b)
    z = max(dp[0] + c, dp[1] + c)
    dp = [x,y,z]
print((max(dp)))
# Original solution
def main():
    N = int(eval(input()))
    A = [0]
    B = [0]
    C = [0]
    for i in range(N):
        a, b, c = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(c)
    dp = [[0 for _ in range(N+1)] for _ in range(3)]
    dp[0][1] = A[1]
    dp[1][1] = B[1]
    dp[2][1] = C[1]

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

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


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    ABC = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[0]*3 for _ in range(N+1)]

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

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


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

def f(n, abc):
    dp = [0] * 3
    for i in range(1, n + 1):
        a, b, c = abc[i - 1]
        dp = [ max(dp[1] + a, dp[2] + a), \
               max(dp[0] + b, dp[2] + b), \
               max(dp[0] + c, dp[1] + c) ]
    return(max(dp))

n = int(eval(input()))    # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print((f(n, abc)))


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

def f(n, abc):
    dp = [0] * 3
    for i in range(n):
        a, b, c = abc[i]
        dp0, dp1, dp2 = dp
        dp = [ max(dp1 + a, dp2 + a), \
               max(dp0 + b, dp2 + b), \
               max(dp0 + c, dp1 + c) ]
    return(max(dp))

n = int(eval(input()))    # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print((f(n, abc)))
# Original 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][0],dp[i-1][2])
  dp[i][2] = c + max(dp[i-1][0],dp[i-1][1])
print((max(dp[n-1])))

# Optimized solution
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n = I()
act = [[0,0,0]] + LLI(n)
dp = [[-10**10,-10**10,-10**10] for _ in range(n+1)]
#dp[i][0]はi日目でA選ぶときの幸福度の最大値
#dp[i][1]はi日目でB選ぶときの幸福度の最大値
#dp[i][2]はi日目でC選ぶときの幸福度の最大値
#1-indexedで考えよう
dp[1] = act[1]
for i in range(2,n+1):
    dp[i][0] = max(dp[i-1][1] + act[i][0], dp[i-1][2] + act[i][0])
    dp[i][1] = max(dp[i-1][0] + act[i][1], dp[i-1][2] + act[i][1])
    dp[i][2] = max(dp[i-1][1] + act[i][2], dp[i-1][0] + act[i][2])
print((max(dp[n][0],dp[n][1],dp[n][2])))
# Original solution
N = int(eval(input()))
dp = [[0] * 3 for _ in range(N)]
action = list(map(int, input().split()))
dp[0][0] = action[0]
dp[0][1] = action[1]
dp[0][2] = action[2]
for i in range(N-1):
    action = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1]+action[0],dp[i][2]+action[0])
    dp[i+1][1] = max(dp[i][0]+action[1],dp[i][2]+action[1])
    dp[i+1][2] = max(dp[i][0]+action[2],dp[i][1]+action[2])
print((max(dp[N-1])))

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


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

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


# Optimized solution
n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(2 * 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])))
# Original solution
import sys
sys.setrecursionlimit(10**8)

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

dp = [[-1] * 4 for i in range(N + 1)]


def happy(n, p):
    if n < 0:
        return 0
    if dp[n][p] >= 0:
        return dp[n][p]

    a = 0 if p == 0 else happy(n - 1, 0) + abc[n][0]
    b = 0 if p == 1 else happy(n - 1, 1) + abc[n][1]
    c = 0 if p == 2 else happy(n - 1, 2) + abc[n][2]
    dp[n][p] = max([a, b, c])

    return dp[n][p]


print((happy(N - 1, 3)))


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

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

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

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

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


for i in range(n):
    if i == 0:
        for j in range(3):
            dp[i][j] = li[i][j]
    else:
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                else:
                    dp[i][j] = max(dp[i-1][k] + li[i][j], dp[i][j])
                    
print((max(dp[-1])))
    

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

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

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

print((max(dp[-1])))
# Original solution
n = int(eval(input()))
d = [[int(e) for e in input().split()] for i in range(n)]
f = [None for i in range(n)]
f[0] = d[0]
for i in range(1, n):
  f[i] = [max(f[i - 1][1] + d[i][0], f[i - 1][2] + d[i][0]), max(f[i - 1][0] + d[i][1], f[i - 1][2] + d[i][1]), max(f[i - 1][0] + d[i][2], f[i - 1][1] + d[i][2])]
print((max(f[n - 1])))


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

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

for i, abc in enumerate(ABC):
  if i == 0:
    for j in range(3):
      DP[i][j] = abc[j]
  else:
    for j in range(3):
      DP[i][j] = max(DP[i-1][k] + abc[j] for k in range(3) if j != k)

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

# Optimized solution
N, = list(map(int, input().split()))

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

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

for i in range(N):
  for j in range(3):
    if i - 1 < 0:
      dp[i][j] += ABC[i][j]
    else:
      x = (j + 1) % 3
      y = (j + 2) % 3
      dp[i][j] = max(dp[i-1][x], dp[i-1][y]) + ABC[i][j]

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


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

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

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


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    abc = [[0, 0, 0] for _ in range(n + 1)]
    for i in range(1, n + 1):
        abc[i] = list(map(int, input().split()))
    dp = [[0, 0, 0] for _ in range(n + 1)]
    dp[1] = abc[1]

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

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


if __name__ == "__main__":
    main()