n=int(eval(input()))

a=[]

for i in range(n):

  a_=list(map(int,input().split()))

  a.append(a_)

  

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

dp[0]=a[0]

for i in range(1,n):

  for k in range(3):

    

    for j in range(3):

      

      if k!=j:

        dp[i][k]=max(dp[i][k], dp[i-1][j] + a[i][k])

#print(dp)        

print((max(dp[n-1])))
n=int(eval(input()))

abc=[[0,0,0]]

for i in range(n):

  labc=list(map(int,input().split()))

  abc.append(labc)



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



for i in range(n):

  for j in range(3):

    if j==0:

      dp[i+1][j]=max(dp[i][1],dp[i][2])+abc[i+1][j]



    elif j==1:

      dp[i+1][j]=max(dp[i][0],dp[i][2])+abc[i+1][j]



    else:

      dp[i+1][j]=max(dp[i][1],dp[i][0])+abc[i+1][j]



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

#print(dp)
n = int(eval(input()))
a = []
for i in range(n):
    a_ = list(map(int, input().split()))
    a.append(a_)
dp = [[0] * 3 for i in range(n)]
dp[0] = a[0]
for i in range(1, n):
    for k in range(3):
        for j in range(3):
            if k != j:
                dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k])
# print(dp)
print((max(dp[n - 1])))

n = int(eval(input()))
abc = [[0, 0, 0]]
for i in range(n):
    labc = list(map(int, input().split()))
    abc.append(labc)
dp = [[0] * 3 for i in range(n + 1)]
for i in range(n):
    for j in range(3):
        if j == 0:
            dp[i + 1][j] = max(dp[i][1], dp[i][2]) + abc[i + 1][j]
        elif j == 1:
            dp[i + 1][j] = max(dp[i][0], dp[i][2]) + abc[i + 1][j]
        else:
            dp[i + 1][j] = max(dp[i][1], dp[i][0]) + abc[i + 1][j]
print((max(dp[n])))
# print(dp)

-a = [] +abc = [[0, 0, 0]] -    a_ = list(map(int, input().split())) -    a.append(a_) -dp = [[0] * 3 for i in range(n)] -dp[0] = a[0] -for i in range(1, n): -    for k in range(3): -        for j in range(3): -            if k != j: -                dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]) +    labc = list(map(int, input().split())) +    abc.append(labc) +dp = [[0] * 3 for i in range(n + 1)] +for i in range(n): +    for j in range(3): +        if j == 0: +            dp[i + 1][j] = max(dp[i][1], dp[i][2]) + abc[i + 1][j] +        elif j == 1: +            dp[i + 1][j] = max(dp[i][0], dp[i][2]) + abc[i + 1][j] +        else: +            dp[i + 1][j] = max(dp[i][1], dp[i][0]) + abc[i + 1][j] +print((max(dp[n]))) -print((max(dp[n - 1])))