from heapq import heappush, heappop N = int(input()) cards = [] for _ in range(N): A, B, C = map(int, input().split()) cards.append((A, B, C)) dp = [(-1, 0, 0)] for i in range(N): pp = [] dp, pp = pp, dp q1 = [] q2 = [] for prev_j, x, tot in pp: for j in range(3): if prev_j == j: continue nx = x + cards[i][j] ntot = tot + nx # dp.append((j, max(0, nx-1), ntot)) heappush(q1, (max(0, nx-1), ntot, j)) heappush(q2, (ntot, max(0, nx-1), j)) if len(q1) > 70: heappop(q1) if len(q2) > 70: heappop(q2) for nx, ntot, j in q1: dp.append((j, nx, ntot)) for ntot, nx, j in q2: dp.append((j, nx, ntot)) ans = max(tot for _, _, tot in dp) print(ans)