import itertools

import math

import sys

from collections import Counter

from fractions import gcd

from functools import reduce

import sys

sys.setrecursionlimit(4100000)



INF = 1 << 60



# ここから書き始める

n = int(eval(input()))

x = [[int(j) for j in input().split()] for i in range(n)]

# print(x)

dp = [[-INF for j in range(3)] for i in range(n)]

for i in range(3):

    dp[0][i] = x[0][i]

for i in range(1, n):

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

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

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

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

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

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



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

# edpc c



import itertools

from math import factorial

import sys

import heapq

from collections import Counter

from collections import deque

from fractions import gcd

from functools import reduce



sys.setrecursionlimit(4100000)

INF = 1 << 60

MOD = 10 ** 9 + 7



# ここから書き始める

n = int(eval(input()))

x = [[] for i in range(n)]

for i in range(n):

    x[i] = list(map(int, input().split()))

# print(x)

dp = [[-INF for j in range(3)] for i in range(n)]

dp[0][0] = x[0][0]

dp[0][1] = x[0][1]

dp[0][2] = x[0][2]

for i in range(1, n):

    a = x[i][0]

    b = x[i][1]

    c = x[i][2]

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

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

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

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

import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys

sys.setrecursionlimit(4100000)
INF = 1 << 60
# ここから書き始める
n = int(eval(input()))
x = [[int(j) for j in input().split()] for i in range(n)]
# print(x)
dp = [[-INF for j in range(3)] for i in range(n)]
for i in range(3):
    dp[0][i] = x[0][i]
for i in range(1, n):
    dp[i][0] = max(dp[i][0], dp[i - 1][1] + x[i][0])
    dp[i][0] = max(dp[i][0], dp[i - 1][2] + x[i][0])
    dp[i][1] = max(dp[i][1], dp[i - 1][0] + x[i][1])
    dp[i][1] = max(dp[i][1], dp[i - 1][2] + x[i][1])
    dp[i][2] = max(dp[i][2], dp[i - 1][0] + x[i][2])
    dp[i][2] = max(dp[i][2], dp[i - 1][1] + x[i][2])
print((max(dp[-1])))

# edpc c
import itertools
from math import factorial
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10**9 + 7
# ここから書き始める
n = int(eval(input()))
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
# print(x)
dp = [[-INF for j in range(3)] for i in range(n)]
dp[0][0] = x[0][0]
dp[0][1] = x[0][1]
dp[0][2] = x[0][2]
for i in range(1, n):
    a = x[i][0]
    b = x[i][1]
    c = x[i][2]
    dp[i][0] = max(dp[i][0], dp[i - 1][1] + a, dp[i - 1][2] + a)
    dp[i][1] = max(dp[i][1], dp[i - 1][0] + b, dp[i - 1][2] + b)
    dp[i][2] = max(dp[i][2], dp[i - 1][0] + c, dp[i - 1][1] + c)
print((max(dp[-1][0], dp[-1][1], dp[-1][2])))

+# edpc c -import math +from math import factorial +import heapq +from collections import deque -import sys +MOD = 10**9 + 7 -x = [[int(j) for j in input().split()] for i in range(n)] +x = [[] for i in range(n)] +for i in range(n): +    x[i] = list(map(int, input().split())) -for i in range(3): -    dp[0][i] = x[0][i] +dp[0][0] = x[0][0] +dp[0][1] = x[0][1] +dp[0][2] = x[0][2] -    dp[i][0] = max(dp[i][0], dp[i - 1][1] + x[i][0]) -    dp[i][0] = max(dp[i][0], dp[i - 1][2] + x[i][0]) -    dp[i][1] = max(dp[i][1], dp[i - 1][0] + x[i][1]) -    dp[i][1] = max(dp[i][1], dp[i - 1][2] + x[i][1]) -    dp[i][2] = max(dp[i][2], dp[i - 1][0] + x[i][2]) -    dp[i][2] = max(dp[i][2], dp[i - 1][1] + x[i][2]) -print((max(dp[-1]))) +    a = x[i][0] +    b = x[i][1] +    c = x[i][2] +    dp[i][0] = max(dp[i][0], dp[i - 1][1] + a, dp[i - 1][2] + a) +    dp[i][1] = max(dp[i][1], dp[i - 1][0] + b, dp[i - 1][2] + b) +    dp[i][2] = max(dp[i][2], dp[i - 1][0] + c, dp[i - 1][1] + c) +print((max(dp[-1][0], dp[-1][1], dp[-1][2])))