import sys

sys.setrecursionlimit(10**6)



n = int(eval(input()))

a, b, c = [], [], []

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

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



for i in range(n):

    v1, v2, v3 = list(map(int, input().split()))

    a.append(v1)

    b.append(v2)

    c.append(v3)



dp[0][0] = a[0]

dp[0][1] = b[0]

dp[0][2] = c[0]



def solve(idx, ptn):

    if dp[idx][ptn] > 0:

        return dp[idx][ptn]



    # Select A(0)

    if ptn == 0:

        if idx == 0:

            return a[0]

        a1 = solve(idx - 1, 1) + a[idx]

        a2 = solve(idx - 1, 2) + a[idx]

        dp[idx][0] = max(a1, a2)

        return dp[idx][0]



    # Select B(1)

    if ptn == 1:

        if idx == 0:

            return b[0]

        b1 = solve(idx - 1, 0) + b[idx]

        b2 = solve(idx - 1, 2) + b[idx]

        dp[idx][1] = max(b1, b2)

        return dp[idx][1]



    # Select C(2)

    if ptn == 2:

        if idx == 0:

            return c[0]

        c1 = solve(idx - 1, 0) + c[idx]

        c2 = solve(idx - 1, 1) + c[idx]

        dp[idx][2] = max(c1, c2)

        return dp[idx][2]



ans1 = solve(n-1, 0)

ans2 = solve(n-1, 1)

ans3 = solve(n-1, 2)

print((max(ans1, ans2, ans3)))
import sys

sys.setrecursionlimit(10**6)



n = int(eval(input()))

a, b, c = [], [], []

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

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



for i in range(n):

    v1, v2, v3 = list(map(int, input().split()))

    a.append(v1)

    b.append(v2)

    c.append(v3)



dp[0][0] = a[0]

dp[0][1] = b[0]

dp[0][2] = c[0]



for idx in range(1, n):

    # Select A(0)

    a1 = dp[idx - 1][1] + a[idx]

    a2 = dp[idx - 1][2] + a[idx]

    dp[idx][0] = max(a1, a2)



    # Select B(1)

    b1 = dp[idx - 1][0] + b[idx]

    b2 = dp[idx - 1][2] + b[idx]

    dp[idx][1] = max(b1, b2)



    # Select C(2)

    c1 = dp[idx - 1][0] + c[idx]

    c2 = dp[idx - 1][1] + c[idx]

    dp[idx][2] = max(c1, c2)



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

sys.setrecursionlimit(10**6)
n = int(eval(input()))
a, b, c = [], [], []
# dp = [[None] * 3 for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
    v1, v2, v3 = list(map(int, input().split()))
    a.append(v1)
    b.append(v2)
    c.append(v3)
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]


def solve(idx, ptn):
    if dp[idx][ptn] > 0:
        return dp[idx][ptn]
    # Select A(0)
    if ptn == 0:
        if idx == 0:
            return a[0]
        a1 = solve(idx - 1, 1) + a[idx]
        a2 = solve(idx - 1, 2) + a[idx]
        dp[idx][0] = max(a1, a2)
        return dp[idx][0]
    # Select B(1)
    if ptn == 1:
        if idx == 0:
            return b[0]
        b1 = solve(idx - 1, 0) + b[idx]
        b2 = solve(idx - 1, 2) + b[idx]
        dp[idx][1] = max(b1, b2)
        return dp[idx][1]
    # Select C(2)
    if ptn == 2:
        if idx == 0:
            return c[0]
        c1 = solve(idx - 1, 0) + c[idx]
        c2 = solve(idx - 1, 1) + c[idx]
        dp[idx][2] = max(c1, c2)
        return dp[idx][2]


ans1 = solve(n - 1, 0)
ans2 = solve(n - 1, 1)
ans3 = solve(n - 1, 2)
print((max(ans1, ans2, ans3)))

import sys

sys.setrecursionlimit(10**6)
n = int(eval(input()))
a, b, c = [], [], []
# dp = [[None] * 3 for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
    v1, v2, v3 = list(map(int, input().split()))
    a.append(v1)
    b.append(v2)
    c.append(v3)
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for idx in range(1, n):
    # Select A(0)
    a1 = dp[idx - 1][1] + a[idx]
    a2 = dp[idx - 1][2] + a[idx]
    dp[idx][0] = max(a1, a2)
    # Select B(1)
    b1 = dp[idx - 1][0] + b[idx]
    b2 = dp[idx - 1][2] + b[idx]
    dp[idx][1] = max(b1, b2)
    # Select C(2)
    c1 = dp[idx - 1][0] + c[idx]
    c2 = dp[idx - 1][1] + c[idx]
    dp[idx][2] = max(c1, c2)
print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))

- - -def solve(idx, ptn): -    if dp[idx][ptn] > 0: -        return dp[idx][ptn] +for idx in range(1, n): -    if ptn == 0: -        if idx == 0: -            return a[0] -        a1 = solve(idx - 1, 1) + a[idx] -        a2 = solve(idx - 1, 2) + a[idx] -        dp[idx][0] = max(a1, a2) -        return dp[idx][0] +    a1 = dp[idx - 1][1] + a[idx] +    a2 = dp[idx - 1][2] + a[idx] +    dp[idx][0] = max(a1, a2) -    if ptn == 1: -        if idx == 0: -            return b[0] -        b1 = solve(idx - 1, 0) + b[idx] -        b2 = solve(idx - 1, 2) + b[idx] -        dp[idx][1] = max(b1, b2) -        return dp[idx][1] +    b1 = dp[idx - 1][0] + b[idx] +    b2 = dp[idx - 1][2] + b[idx] +    dp[idx][1] = max(b1, b2) -    if ptn == 2: -        if idx == 0: -            return c[0] -        c1 = solve(idx - 1, 0) + c[idx] -        c2 = solve(idx - 1, 1) + c[idx] -        dp[idx][2] = max(c1, c2) -        return dp[idx][2] - - -ans1 = solve(n - 1, 0) -ans2 = solve(n - 1, 1) -ans3 = solve(n - 1, 2) -print((max(ans1, ans2, ans3))) +    c1 = dp[idx - 1][0] + c[idx] +    c2 = dp[idx - 1][1] + c[idx] +    dp[idx][2] = max(c1, c2) +print((max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])))