N = int(eval(input()))

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

#print(X)

dp = [[0] * 3 for _ 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][j] = max(dp[i + 1][j], dp[i][k] + X[i][j])	

ans=0

for j in range(3):

  ans=max(ans,dp[N][j])

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]*(N+1)

for i in range(N):

  if i==0:

    dp[i][0]=L[i][0]

    dp[i][1]=L[i][1]

    dp[i][2]=L[i][2]

  else:

    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]

  ans=max(dp[i][0],dp[i][1],dp[i][2])

  #print(ans)

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

-X = [list(map(int, input().split())) for i in range(N)] -# print(X) -dp = [[0] * 3 for _ in range(N + 1)] +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] * (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] + X[i][j]) -ans = 0 -for j in range(3): -    ans = max(ans, dp[N][j]) +    if i == 0: +        dp[i][0] = L[i][0] +        dp[i][1] = L[i][1] +        dp[i][2] = L[i][2] +    else: +        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] +    ans = max(dp[i][0], dp[i][1], dp[i][2]) +    # print(ans)