n=int(eval(input()))

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

dpa=[0]*n

dpb=[0]*n

dpc=[0]*n

dpa[0]=a[0][0]

dpb[0]=a[0][1]

dpc[0]=a[0][2]

for i in range(1,n):

    dpa[i]=max(dpb[i-1]+a[i][0],dpc[i-1]+a[i][0])

    dpb[i]=max(dpa[i-1]+a[i][1],dpc[i-1]+a[i][1])

    dpc[i]=max(dpb[i-1]+a[i][2],dpa[i-1]+a[i][2])

#print(dpa,dpb,dpc)

print((max(dpa[-1],dpb[-1],dpc[-1])))
n =int(eval(input()))

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



dp = [[0 for i in range(3)] for j in range(n)]



for i in range(n):

  if i==0:

    dp[0]=l[0]

  else:

    dp[i][0]=max(dp[i][0],dp[i-1][1]+l[i][0],dp[i-1][2]+l[i][0])

    dp[i][1]=max(dp[i][1],dp[i-1][0]+l[i][1],dp[i-1][2]+l[i][1])

    dp[i][2]=max(dp[i][2],dp[i-1][0]+l[i][2],dp[i-1][1]+l[i][2])

print((max(dp[n-1])))
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
dpa = [0] * n
dpb = [0] * n
dpc = [0] * n
dpa[0] = a[0][0]
dpb[0] = a[0][1]
dpc[0] = a[0][2]
for i in range(1, n):
    dpa[i] = max(dpb[i - 1] + a[i][0], dpc[i - 1] + a[i][0])
    dpb[i] = max(dpa[i - 1] + a[i][1], dpc[i - 1] + a[i][1])
    dpc[i] = max(dpb[i - 1] + a[i][2], dpa[i - 1] + a[i][2])
# print(dpa,dpb,dpc)
print((max(dpa[-1], dpb[-1], dpc[-1])))

n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n)]
dp = [[0 for i in range(3)] for j in range(n)]
for i in range(n):
    if i == 0:
        dp[0] = l[0]
    else:
        dp[i][0] = max(dp[i][0], dp[i - 1][1] + l[i][0], dp[i - 1][2] + l[i][0])
        dp[i][1] = max(dp[i][1], dp[i - 1][0] + l[i][1], dp[i - 1][2] + l[i][1])
        dp[i][2] = max(dp[i][2], dp[i - 1][0] + l[i][2], dp[i - 1][1] + l[i][2])
print((max(dp[n - 1])))

-a = [list(map(int, input().split())) for i in range(n)] -dpa = [0] * n -dpb = [0] * n -dpc = [0] * n -dpa[0] = a[0][0] -dpb[0] = a[0][1] -dpc[0] = a[0][2] -for i in range(1, n): -    dpa[i] = max(dpb[i - 1] + a[i][0], dpc[i - 1] + a[i][0]) -    dpb[i] = max(dpa[i - 1] + a[i][1], dpc[i - 1] + a[i][1]) -    dpc[i] = max(dpb[i - 1] + a[i][2], dpa[i - 1] + a[i][2]) -# print(dpa,dpb,dpc) -print((max(dpa[-1], dpb[-1], dpc[-1]))) +l = [list(map(int, input().split())) for i in range(n)] +dp = [[0 for i in range(3)] for j in range(n)] +for i in range(n): +    if i == 0: +        dp[0] = l[0] +    else: +        dp[i][0] = max(dp[i][0], dp[i - 1][1] + l[i][0], dp[i - 1][2] + l[i][0]) +        dp[i][1] = max(dp[i][1], dp[i - 1][0] + l[i][1], dp[i - 1][2] + l[i][1]) +        dp[i][2] = max(dp[i][2], dp[i - 1][0] + l[i][2], dp[i - 1][1] + l[i][2]) +print((max(dp[n - 1])))