def main():

    n = int(eval(input()))

    matrix = []

    tb = [[0] * 4 for _ in range(n + 1)]

    for _ in range(n):

        matrix.append([int(e) for e in input().split()])

    

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

        for j in range(1, 4):

            for l in range(1, 4):

                if j == l: continue

                tb[i][j] = max(tb[i][j], tb[i - 1][l] + matrix[i - 1][j - 1])

    

    print((max(tb[n])))

    return 0



if __name__ == "__main__":

    main()
def main():

    n, factor = getInputs()



    points = []

    for i in range(n):

        points.append([0] * 3)



    # points[day][pile]

    for pile in range(3):

        points[0][pile] = factor[0][pile]



    for day in range(1, n):

        points[day][0] = max(points[day - 1][1], points[day - 1][2]) + factor[day][0]

        points[day][1] = max(points[day - 1][0], points[day - 1][2]) + factor[day][1]

        points[day][2] = max(points[day - 1][0], points[day - 1][1]) + factor[day][2]



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



def getInputs():

    n = int(eval(input()))



    factor = []

    for i in range(n):

        factor.append(tuple([int(x) for x in input().split()]))



    return n, factor



main()

def main():
    n = int(eval(input()))
    matrix = []
    tb = [[0] * 4 for _ in range(n + 1)]
    for _ in range(n):
        matrix.append([int(e) for e in input().split()])
    for i in range(1, n + 1):
        for j in range(1, 4):
            for l in range(1, 4):
                if j == l:
                    continue
                tb[i][j] = max(tb[i][j], tb[i - 1][l] + matrix[i - 1][j - 1])
    print((max(tb[n])))
    return 0


if __name__ == "__main__":
    main()

def main():
    n, factor = getInputs()
    points = []
    for i in range(n):
        points.append([0] * 3)
    # points[day][pile]
    for pile in range(3):
        points[0][pile] = factor[0][pile]
    for day in range(1, n):
        points[day][0] = max(points[day - 1][1], points[day - 1][2]) + factor[day][0]
        points[day][1] = max(points[day - 1][0], points[day - 1][2]) + factor[day][1]
        points[day][2] = max(points[day - 1][0], points[day - 1][1]) + factor[day][2]
    print((max(points[-1])))


def getInputs():
    n = int(eval(input()))
    factor = []
    for i in range(n):
        factor.append(tuple([int(x) for x in input().split()]))
    return n, factor


main()

-    n = int(eval(input())) -    matrix = [] -    tb = [[0] * 4 for _ in range(n + 1)] -    for _ in range(n): -        matrix.append([int(e) for e in input().split()]) -    for i in range(1, n + 1): -        for j in range(1, 4): -            for l in range(1, 4): -                if j == l: -                    continue -                tb[i][j] = max(tb[i][j], tb[i - 1][l] + matrix[i - 1][j - 1]) -    print((max(tb[n]))) -    return 0 +    n, factor = getInputs() +    points = [] +    for i in range(n): +        points.append([0] * 3) +    # points[day][pile] +    for pile in range(3): +        points[0][pile] = factor[0][pile] +    for day in range(1, n): +        points[day][0] = max(points[day - 1][1], points[day - 1][2]) + factor[day][0] +        points[day][1] = max(points[day - 1][0], points[day - 1][2]) + factor[day][1] +        points[day][2] = max(points[day - 1][0], points[day - 1][1]) + factor[day][2] +    print((max(points[-1]))) -if __name__ == "__main__": -    main() +def getInputs(): +    n = int(eval(input())) +    factor = [] +    for i in range(n): +        factor.append(tuple([int(x) for x in input().split()])) +    return n, factor + + +main()