n=int(eval(input()))

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

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

dp[0]=list(map(int,input().split()))

S[0]=dp[0].copy()

for i in range(1,n):

    S[i]=list(map(int,input().split()))

    for j in range(3):

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



print((max(dp[n-1][0],dp[n-1][1],dp[n-1][2])))

#dp[i][j]=i番目にjを選んだ時の最大値(jはa,b,cに対応している。)
n=int(eval(input()))

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

dp[0]=list(map(int,input().split()))

for i in range(1,n):

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

    for j in range(3):

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



print((max(dp[n-1][0],dp[n-1][1],dp[n-1][2])))

#dp[i][j]=i番目にjを選んだ時の最大値(jはa,b,cに対応している。)
n = int(eval(input()))
dp = [[0 for i in range(3)] for i in range(n)]
S = [[0 for i in range(3)] for i in range(n)]
dp[0] = list(map(int, input().split()))
S[0] = dp[0].copy()
for i in range(1, n):
    S[i] = list(map(int, input().split()))
    for j in range(3):
        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + S[i][j]
print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))
# dp[i][j]=i番目にjを選んだ時の最大値(jはa,b,cに対応している。)

n = int(eval(input()))
dp = [[0 for i in range(3)] for i in range(n)]
dp[0] = list(map(int, input().split()))
for i in range(1, n):
    S = list(map(int, input().split()))
    for j in range(3):
        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + S[j]
print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))
# dp[i][j]=i番目にjを選んだ時の最大値(jはa,b,cに対応している。)

-S = [[0 for i in range(3)] for i in range(n)] -S[0] = dp[0].copy() -    S[i] = list(map(int, input().split())) +    S = list(map(int, input().split())) -        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + S[i][j] +        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + S[j]