def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10000000)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations

    #from itertools import accumulate, product

    from bisect import bisect_left,bisect_right

    from math import floor, ceil

    #from operator import itemgetter



    #mod = 1000000007



    N = int(eval(input()))

    l = [list(map(int, input().split())) for _ in range(N)]

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

    dp[1] = l[0]

    

    for i in range(1, N):

        for j in range(3):

            a = (j+1)%3

            b = (j+2)%3

            dp[i+1][j] = max(dp[i][a], dp[i][b]) + l[i][j]

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



if __name__ == '__main__':

    main()
import sys

input = sys.stdin.readline

n = int(eval(input()))

a = [0]*n

b = [0]*n

c = [0]*n

for i in range(n):

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



dpa = [a[0]]+[0]*(n-1)

dpb = [b[0]]+[0]*(n-1)

dpc = [c[0]]+[0]*(n-1)

for i in range(1,n):

    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]

    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]

    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]

print((max(dpa[-1],dpb[-1],dpc[-1])))
def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations

    # from itertools import accumulate, product
    from bisect import bisect_left, bisect_right
    from math import floor, ceil

    # from operator import itemgetter
    # mod = 1000000007
    N = int(eval(input()))
    l = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0] * 3 for _ in range(N + 1)]
    dp[1] = l[0]
    for i in range(1, N):
        for j in range(3):
            a = (j + 1) % 3
            b = (j + 2) % 3
            dp[i + 1][j] = max(dp[i][a], dp[i][b]) + l[i][j]
    print((max(dp[N])))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
n = int(eval(input()))
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
    a[i], b[i], c[i] = list(map(int, input().split()))
dpa = [a[0]] + [0] * (n - 1)
dpb = [b[0]] + [0] * (n - 1)
dpc = [c[0]] + [0] * (n - 1)
for i in range(1, n):
    dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i]
    dpb[i] = max(dpc[i - 1], dpa[i - 1]) + b[i]
    dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c[i]
print((max(dpa[-1], dpb[-1], dpc[-1])))

-def main(): -    import sys +import sys -    input = sys.stdin.readline -    sys.setrecursionlimit(10000000) -    from collections import Counter, deque - -    # from collections import defaultdict -    from itertools import combinations, permutations - -    # from itertools import accumulate, product -    from bisect import bisect_left, bisect_right -    from math import floor, ceil - -    # from operator import itemgetter -    # mod = 1000000007 -    N = int(eval(input())) -    l = [list(map(int, input().split())) for _ in range(N)] -    dp = [[0] * 3 for _ in range(N + 1)] -    dp[1] = l[0] -    for i in range(1, N): -        for j in range(3): -            a = (j + 1) % 3 -            b = (j + 2) % 3 -            dp[i + 1][j] = max(dp[i][a], dp[i][b]) + l[i][j] -    print((max(dp[N]))) - - -if __name__ == "__main__": -    main() +input = sys.stdin.readline +n = int(eval(input())) +a = [0] * n +b = [0] * n +c = [0] * n +for i in range(n): +    a[i], b[i], c[i] = list(map(int, input().split())) +dpa = [a[0]] + [0] * (n - 1) +dpb = [b[0]] + [0] * (n - 1) +dpc = [c[0]] + [0] * (n - 1) +for i in range(1, n): +    dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i] +    dpb[i] = max(dpc[i - 1], dpa[i - 1]) + b[i] +    dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c[i] +print((max(dpa[-1], dpb[-1], dpc[-1])))