import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n = int(input().rstrip('\n'))

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

    for i in range(n):

        a, b, c = list(map(int, input().rstrip('\n').split()))

        if i == 0:

            dp[i][0] = a

            dp[i][1] = b

            dp[i][2] = c

        else:

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

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



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

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



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

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

    print((max(dp[-1])))





if __name__ == '__main__':

    solve()

import sys





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

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

    for i in range(n):

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

        if i == 0:

            dp[i][0] = a

            dp[i][1] = b

            dp[i][2] = c

        else:

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

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

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

    print((max(dp[-1])))





if __name__ == '__main__':

    solve()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n = int(input().rstrip("\n"))
    dp = [[0] * 3 for _ in range(n)]
    for i in range(n):
        a, b, c = list(map(int, input().rstrip("\n").split()))
        if i == 0:
            dp[i][0] = a
            dp[i][1] = b
            dp[i][2] = c
        else:
            dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
            dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
            dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
            dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
            dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
            dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
    print((max(dp[-1])))


if __name__ == "__main__":
    solve()

import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    dp = [[0] * 3 for _ in range(n)]
    for i in range(n):
        a, b, c = list(map(int, readline().split()))
        if i == 0:
            dp[i][0] = a
            dp[i][1] = b
            dp[i][2] = c
        else:
            dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
            dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
            dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
    print((max(dp[-1])))


if __name__ == "__main__":
    solve()

-    input = sys.stdin.readline +    readline = sys.stdin.buffer.readline -    n = int(input().rstrip("\n")) +    n = int(readline()) -        a, b, c = list(map(int, input().rstrip("\n").split())) +        a, b, c = list(map(int, readline().split())) -            dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a) -            dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b) -            dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)