N=int(eval(input()))

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

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

ans=0

for i in range(N):

  for P in range(3):

    for PY in range(3):

      if P==PY:

        continue

      elif i==0:

        dp[i][P]=L[i][P]

        ans=max(ans,dp[i][P])

      else:

        dp[i][P]=max(dp[i][P],dp[i-1][PY]+L[i][P])

        ans=max(ans,dp[i][P])

'''

for i in range(3):

  ans=max(ans,dp[N-1][i])

'''

print(ans)

  
N=int(eval(input()))

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

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



for i in range(N):

  for P in range(3):

    for PY in range(3):

      if P==PY:

        continue

      elif i==0:

        dp[i][P]=L[i][P]

      else:

        dp[i][P]=max(dp[i][P],dp[i-1][PY]+L[i][P])

ans=0

for i in range(3):

  ans=max(ans,dp[N-1][i])

print(ans)
N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(3)] for i in range(N)]
ans = 0
for i in range(N):
    for P in range(3):
        for PY in range(3):
            if P == PY:
                continue
            elif i == 0:
                dp[i][P] = L[i][P]
                ans = max(ans, dp[i][P])
            else:
                dp[i][P] = max(dp[i][P], dp[i - 1][PY] + L[i][P])
                ans = max(ans, dp[i][P])
"""
for i in range(3):
  ans=max(ans,dp[N-1][i])
"""
print(ans)

N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(3)] for i in range(N)]
for i in range(N):
    for P in range(3):
        for PY in range(3):
            if P == PY:
                continue
            elif i == 0:
                dp[i][P] = L[i][P]
            else:
                dp[i][P] = max(dp[i][P], dp[i - 1][PY] + L[i][P])
ans = 0
for i in range(3):
    ans = max(ans, dp[N - 1][i])
print(ans)

-ans = 0 -                ans = max(ans, dp[i][P]) -                ans = max(ans, dp[i][P]) -""" +ans = 0 -  ans=max(ans,dp[N-1][i]) -""" +    ans = max(ans, dp[N - 1][i])