def main():

    N = int(eval(input()))

    A = [0]

    B = [0]

    C = [0]

    for i in range(N):

        a, b, c = (int(i) for i in input().split())

        A.append(a)

        B.append(b)

        C.append(c)

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

    dp[0][1] = A[1]

    dp[1][1] = B[1]

    dp[2][1] = C[1]



    for i in range(1, N):

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

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

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



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





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    ABC = [[int(i) for i in input().split()] for j in range(N)]

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



    for i in range(N):

        for j in range(3):

            dp[i+1][j] = max(dp[i][(j+1) % 3], dp[i][(j+2) % 3]) + ABC[i][j]



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





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A = [0]
    B = [0]
    C = [0]
    for i in range(N):
        a, b, c = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(c)
    dp = [[0 for _ in range(N + 1)] for _ in range(3)]
    dp[0][1] = A[1]
    dp[1][1] = B[1]
    dp[2][1] = C[1]
    for i in range(1, N):
        dp[2][i + 1] = max(dp[0][i] + C[i + 1], dp[1][i] + C[i + 1])
        dp[1][i + 1] = max(dp[0][i] + B[i + 1], dp[2][i] + B[i + 1])
        dp[0][i + 1] = max(dp[1][i] + A[i + 1], dp[2][i] + A[i + 1])
    print((max(dp[0][-1], dp[1][-1], dp[2][-1])))


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    ABC = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[0] * 3 for _ in range(N + 1)]
    for i in range(N):
        for j in range(3):
            dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + ABC[i][j]
    print((max(dp[N])))


if __name__ == "__main__":
    main()

-    A = [0] -    B = [0] -    C = [0] +    ABC = [[int(i) for i in input().split()] for j in range(N)] +    dp = [[0] * 3 for _ in range(N + 1)] -        a, b, c = (int(i) for i in input().split()) -        A.append(a) -        B.append(b) -        C.append(c) -    dp = [[0 for _ in range(N + 1)] for _ in range(3)] -    dp[0][1] = A[1] -    dp[1][1] = B[1] -    dp[2][1] = C[1] -    for i in range(1, N): -        dp[2][i + 1] = max(dp[0][i] + C[i + 1], dp[1][i] + C[i + 1]) -        dp[1][i + 1] = max(dp[0][i] + B[i + 1], dp[2][i] + B[i + 1]) -        dp[0][i + 1] = max(dp[1][i] + A[i + 1], dp[2][i] + A[i + 1]) -    print((max(dp[0][-1], dp[1][-1], dp[2][-1]))) +        for j in range(3): +            dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + ABC[i][j] +    print((max(dp[N])))