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

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

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

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

-l1 = [] -l2 = [] -l3 = [] +l = [] -    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] +    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] -    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]))) +    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])))