class Solver(object):

    def __init__(self, N, happy):

        self.dp = [[99999999 for _ in range(3)] for _ in range(N)]

        self.N = N

        self.happy = happy



    def solve(self):

        happy_list = self.happy

        self.dp[0] = happy_list[0]

        for i in range(1, self.N):

            self.dp[i][0] = max(happy_list[i][0] + self.dp[i-1][1],

                                happy_list[i][0] + self.dp[i-1][2])

            self.dp[i][1] = max(happy_list[i][1] + self.dp[i-1][0],

                                happy_list[i][1] + self.dp[i-1][2])

            self.dp[i][2] = max(happy_list[i][2] + self.dp[i-1][0],

                                happy_list[i][2] + self.dp[i - 1][1])

        return max(self.dp[-1])





def main():

    N = int(eval(input()))

    happy = [[int(i) for i in input().split()] for _ in range(N)]

    solver = Solver(N, happy)

    print((solver.solve()))





if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline

# sys.setrecursionlimit(100000)





def main():

    N = int(input().strip())

    happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]

    dp = [[None, None, None] for _ in range(N)]



    dp[0] = happy_list[0]



    for i in range(1, N):

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

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

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



    return max(dp[-1])





if __name__ == "__main__":

    print((main()))

class Solver(object):
    def __init__(self, N, happy):
        self.dp = [[99999999 for _ in range(3)] for _ in range(N)]
        self.N = N
        self.happy = happy

    def solve(self):
        happy_list = self.happy
        self.dp[0] = happy_list[0]
        for i in range(1, self.N):
            self.dp[i][0] = max(
                happy_list[i][0] + self.dp[i - 1][1],
                happy_list[i][0] + self.dp[i - 1][2],
            )
            self.dp[i][1] = max(
                happy_list[i][1] + self.dp[i - 1][0],
                happy_list[i][1] + self.dp[i - 1][2],
            )
            self.dp[i][2] = max(
                happy_list[i][2] + self.dp[i - 1][0],
                happy_list[i][2] + self.dp[i - 1][1],
            )
        return max(self.dp[-1])


def main():
    N = int(eval(input()))
    happy = [[int(i) for i in input().split()] for _ in range(N)]
    solver = Solver(N, happy)
    print((solver.solve()))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
# sys.setrecursionlimit(100000)
def main():
    N = int(input().strip())
    happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]
    dp = [[None, None, None] for _ in range(N)]
    dp[0] = happy_list[0]
    for i in range(1, N):
        dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2])
        dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2])
        dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1])
    return max(dp[-1])


if __name__ == "__main__":
    print((main()))

-class Solver(object): -    def __init__(self, N, happy): -        self.dp = [[99999999 for _ in range(3)] for _ in range(N)] -        self.N = N -        self.happy = happy +import sys -    def solve(self): -        happy_list = self.happy -        self.dp[0] = happy_list[0] -        for i in range(1, self.N): -            self.dp[i][0] = max( -                happy_list[i][0] + self.dp[i - 1][1], -                happy_list[i][0] + self.dp[i - 1][2], -            ) -            self.dp[i][1] = max( -                happy_list[i][1] + self.dp[i - 1][0], -                happy_list[i][1] + self.dp[i - 1][2], -            ) -            self.dp[i][2] = max( -                happy_list[i][2] + self.dp[i - 1][0], -                happy_list[i][2] + self.dp[i - 1][1], -            ) -        return max(self.dp[-1]) - - +input = sys.stdin.readline +# sys.setrecursionlimit(100000) -    N = int(eval(input())) -    happy = [[int(i) for i in input().split()] for _ in range(N)] -    solver = Solver(N, happy) -    print((solver.solve())) +    N = int(input().strip()) +    happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)] +    dp = [[None, None, None] for _ in range(N)] +    dp[0] = happy_list[0] +    for i in range(1, N): +        dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2]) +        dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2]) +        dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1]) +    return max(dp[-1]) -    main() +    print((main()))