n = int(eval(input()))

h = []

for _ in range(n):

    a, b, c = [int(x) for x in input().split()]

    h.append((a, b, c))



vals = {}

a, b, c = h[0]

vals[(0, 'A')] = a

vals[(0, 'B')] = b

vals[(0, 'C')] = c



for i in range(1, n):

    a, b, c = h[i]

    vals[(i, 'A')] = max(vals[(i-1, 'B')], vals[(i-1, 'C')]) + a

    vals[(i, 'B')] = max(vals[(i-1, 'A')], vals[(i-1, 'C')]) + b

    vals[(i, 'C')] = max(vals[(i-1, 'B')], vals[(i-1, 'A')]) + c



print((max(vals[(n-1, 'A')], vals[(n-1, 'B')], vals[(n-1, 'C')])))

n = int(eval(input()))

a=[0] * (n+1)

b=[0] * (n+1)

c=[0] * (n+1)

aux = [ [0] * 5 for _ in range(n+1)]



for i in range(1,n+1):

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



a = [int(i) for i in a]

b = [int(i) for i in b]

c = [int(i) for i in c]



aux[1][1]=a[1]

aux[1][2]=b[1]

aux[1][3]=c[1]







for i in range(2,n+1):

    aux[i][1]+=max(aux[i-1][2],aux[i-1][3])+a[i]

    aux[i][2]+=max(aux[i-1][1],aux[i-1][3])+b[i]

    aux[i][3]+=max(aux[i-1][1],aux[i-1][2])+c[i]



print((max(aux[n][1],aux[n][2],aux[n][3])))
n = int(eval(input()))
h = []
for _ in range(n):
    a, b, c = [int(x) for x in input().split()]
    h.append((a, b, c))
vals = {}
a, b, c = h[0]
vals[(0, "A")] = a
vals[(0, "B")] = b
vals[(0, "C")] = c
for i in range(1, n):
    a, b, c = h[i]
    vals[(i, "A")] = max(vals[(i - 1, "B")], vals[(i - 1, "C")]) + a
    vals[(i, "B")] = max(vals[(i - 1, "A")], vals[(i - 1, "C")]) + b
    vals[(i, "C")] = max(vals[(i - 1, "B")], vals[(i - 1, "A")]) + c
print((max(vals[(n - 1, "A")], vals[(n - 1, "B")], vals[(n - 1, "C")])))

n = int(eval(input()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
aux = [[0] * 5 for _ in range(n + 1)]
for i in range(1, n + 1):
    a[i], b[i], c[i] = input().split()
a = [int(i) for i in a]
b = [int(i) for i in b]
c = [int(i) for i in c]
aux[1][1] = a[1]
aux[1][2] = b[1]
aux[1][3] = c[1]
for i in range(2, n + 1):
    aux[i][1] += max(aux[i - 1][2], aux[i - 1][3]) + a[i]
    aux[i][2] += max(aux[i - 1][1], aux[i - 1][3]) + b[i]
    aux[i][3] += max(aux[i - 1][1], aux[i - 1][2]) + c[i]
print((max(aux[n][1], aux[n][2], aux[n][3])))

-h = [] -for _ in range(n): -    a, b, c = [int(x) for x in input().split()] -    h.append((a, b, c)) -vals = {} -a, b, c = h[0] -vals[(0, "A")] = a -vals[(0, "B")] = b -vals[(0, "C")] = c -for i in range(1, n): -    a, b, c = h[i] -    vals[(i, "A")] = max(vals[(i - 1, "B")], vals[(i - 1, "C")]) + a -    vals[(i, "B")] = max(vals[(i - 1, "A")], vals[(i - 1, "C")]) + b -    vals[(i, "C")] = max(vals[(i - 1, "B")], vals[(i - 1, "A")]) + c -print((max(vals[(n - 1, "A")], vals[(n - 1, "B")], vals[(n - 1, "C")]))) +a = [0] * (n + 1) +b = [0] * (n + 1) +c = [0] * (n + 1) +aux = [[0] * 5 for _ in range(n + 1)] +for i in range(1, n + 1): +    a[i], b[i], c[i] = input().split() +a = [int(i) for i in a] +b = [int(i) for i in b] +c = [int(i) for i in c] +aux[1][1] = a[1] +aux[1][2] = b[1] +aux[1][3] = c[1] +for i in range(2, n + 1): +    aux[i][1] += max(aux[i - 1][2], aux[i - 1][3]) + a[i] +    aux[i][2] += max(aux[i - 1][1], aux[i - 1][3]) + b[i] +    aux[i][3] += max(aux[i - 1][1], aux[i - 1][2]) + c[i] +print((max(aux[n][1], aux[n][2], aux[n][3])))