import sys

input = sys.stdin.readline

import numpy as np

N = int(eval(input()))

dp = np.zeros((N+1,3), dtype=np.int)

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

for _ in range(3):

  dp[1][_] = X[_]

for n in range(2,N+1):

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

  dp[n][0] = max(dp[n-1][1],dp[n-1][2]) + X[0]

  dp[n][1] = max(dp[n-1][2],dp[n-1][0]) + X[1]

  dp[n][2] = max(dp[n-1][0],dp[n-1][1]) + X[2]

print((max(dp[N])))
#!/usr/bin python3

# -*- coding: utf-8 -*-



def main():

    N = int(eval(input()))

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

    #dp[i][j] iまでで、j=0はaを選ぶ,j=1はbを選ぶ,j=2はcを選ぶ

    for i in range(1,N+1):

        a, b, c=list(map(int,input().split()))

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

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

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



    print((max(dp[N])))



if __name__ == '__main__':

    main()
import sys

input = sys.stdin.readline
import numpy as np

N = int(eval(input()))
dp = np.zeros((N + 1, 3), dtype=np.int)
X = list(map(int, input().split()))
for _ in range(3):
    dp[1][_] = X[_]
for n in range(2, N + 1):
    X = list(map(int, input().split()))
    dp[n][0] = max(dp[n - 1][1], dp[n - 1][2]) + X[0]
    dp[n][1] = max(dp[n - 1][2], dp[n - 1][0]) + X[1]
    dp[n][2] = max(dp[n - 1][0], dp[n - 1][1]) + X[2]
print((max(dp[N])))

#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
    N = int(eval(input()))
    dp = [[0] * 3 for i in range(N + 1)]
    # dp[i][j] iまでで、j=0はaを選ぶ,j=1はbを選ぶ,j=2はcを選ぶ
    for i in range(1, N + 1):
        a, b, c = list(map(int, input().split()))
        dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a, dp[i][0])
        dp[i][1] = max(dp[i - 1][2] + b, dp[i - 1][0] + b, dp[i][1])
        dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c, dp[i][2])
    print((max(dp[N])))


if __name__ == "__main__":
    main()

-import sys +#!/usr/bin python3 +# -*- coding: utf-8 -*- +def main(): +    N = int(eval(input())) +    dp = [[0] * 3 for i in range(N + 1)] +    # dp[i][j] iまでで、j=0はaを選ぶ,j=1はbを選ぶ,j=2はcを選ぶ +    for i in range(1, N + 1): +        a, b, c = list(map(int, input().split())) +        dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a, dp[i][0]) +        dp[i][1] = max(dp[i - 1][2] + b, dp[i - 1][0] + b, dp[i][1]) +        dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c, dp[i][2]) +    print((max(dp[N]))) -input = sys.stdin.readline -import numpy as np -N = int(eval(input())) -dp = np.zeros((N + 1, 3), dtype=np.int) -X = list(map(int, input().split())) -for _ in range(3): -    dp[1][_] = X[_] -for n in range(2, N + 1): -    X = list(map(int, input().split())) -    dp[n][0] = max(dp[n - 1][1], dp[n - 1][2]) + X[0] -    dp[n][1] = max(dp[n - 1][2], dp[n - 1][0]) + X[1] -    dp[n][2] = max(dp[n - 1][0], dp[n - 1][1]) + X[2] -print((max(dp[N]))) +if __name__ == "__main__": +    main()